Elektroda.com
Elektroda.com
X

STM32 Blue Pill - an alternative to Arduino

ghost666 14763 58
This content has been translated flag-pl » flag-en View the original version here.
  • STM32 Blue Pill - an alternative to Arduino
    Everyone likes Arduino, from the smallest modules on Attiny85 to the largest modules based on MEGA2560 microcontrollers. Unfortunately, they have their limitations - if we need more computing power, higher precision or more analog inputs, we do not have much choice in the Arduino family ... There is, however, an elegant solution that will ensure that we do not have to leave this ecosystem at all.

    There is a board compatible with Arduino nano with a microcontroller from the STM32 family - Blue Pill. Unfortunately - there is a catch here - it cannot be programmed via USB, because the system does not have a pre-programmed bootloader (it is a small program that works a bit like an operating system on a microcontroller and allows you to upload software via USB.

    In the following instructions, we will learn how to easily upload an Arduino-compatible bootloader to the system, thanks to which we will be able to program these systems with the Arduino IDE, just like any other module from this ecosystem.

    STM32 Blue Pill - an alternative to Arduino
    STM32 Blue Pill - an alternative to Arduino
    Step 1: What we will need

    Of course, we need the tile itself - you can buy it on eBay, AliExpress or Allegro.

    In addition to the module itself, we also need a USB to UART TTL converter to upload the first program - bootloader - to the microcontroller's memory. An example converter is shown in the photo in the article. In principle, any converter will do.

    Finally, of course, we need cables to connect the controller to the module, but this is something that every Arduino enthusiast definitely has in his workshop.

    Step 2: Configuring the Arduino IDE

    Before we start connecting and programming Blue Pill via the Arduino IDE, we need to do a few simple things. First of all - we need to load the configuration data for this chip into our environment. For this purpose, in the Arduino IDE, press File and select the Preferences menu. A new window will open, in which we need to find an icon with the description "Additional Boards Manager URLs:" There we add a link to the configuration file for STM32: http://dan.drown.org/stm32duino/package_STM32duino_index.json .

    If there is already something here, just add another entry on a new line. We can now close the Arduino IDE and restart it. Now select the boards and Board Manager tab in the Tools menu (it is the first on the list). In the "Filter your search ..." box, type stm32f1 to filter the available options. There should be one search result. When we find the correct driver, we can click on it to install it in our IDE. After that, we can turn off the Arduino IDE - its configuration is finished.

    STM32 Blue Pill - an alternative to Arduino


    STM32 Blue Pill - an alternative to Arduino
    STM32 Blue Pill - an alternative to Arduino
    Step 3: Drivers

    After connecting Blue Pill to the computer, Windows will not automatically detect this device, it is necessary to install drivers. It's also a very simple process. We start with downloading the drivers. They are located here .

    After entering the repository, press the green button "Clone or Download" and select "Download ZIP". After downloading it, download the package and copy it to the folder with the Arduino IDE. If we installed the software in the default location, we will find it in C: \ Program files (x86) \ Arduino. We find or create a folder under the name "hardware" and copy the file "Arduino_STM32-master" from the downloaded ZIP file there. Let's change its name to Arduino_STM32.

    At this stage, the software preparation is almost ready. There is only one more step ahead of us.

    STM32 Blue Pill - an alternative to Arduino
    Step 4: Loading the bootloader

    We need to upload the bootloader. For this, we need two things - the program udo loading the firmware to STM32, which can be downloaded here (you need to register on the site and you will be able to download it) and the bootlader itself in binary form, which can be found in this repository . Select the file "generic_boot_pc13.bit" and simply download it.

    Now we have everything we need. We need to connect the USB-UART converter to Blue Pill and load it. The connections are very simple as described in the table:





    USB UART converter Blue Pill
    TX A10
    RX A9
    VCC 3.3 V
    mass GND


    We also set the highest jumper on the module with STM32 in the right position. We can now connect the converter to the USB port on the computer.

    Now we can install the software we downloaded. Just click on the downloaded installer and follow the instructions. After starting it, you should see a new COM port in the programmer. If it does not appear in our system, you need to check all connections in our system and run the program again.

    After correctly detecting the COM port, click "Next" three times, and finally we get to the window where we can select the "Download to device" option. Select the "Download from file" option there, and locate the previously downloaded bootloader file. Then click OK and "Next" again. The program will automatically install the new firmware. The program can now be loaded but can not yet disconnect the boards from the computer.

    First we put the top jumper back to the left position so that both jumpers are in the zero position. Now we can disconnect everything.

    STM32 Blue Pill - an alternative to Arduino
    STM32 Blue Pill - an alternative to Arduino
    Step 5: First Program

    We can now connect Blue Pill to the computer and run the Arduino IDE. In the Boards menu, select "Generic STM32F103C series". Then select the program loading option - "STM32duino bootloader", where the port is "COMX (Maple Mini)" where X is the number that our computer assigned to the new serial port.

    Now Blue Pill is recognized as Maple Mini. We can start writing and loading sketches in the Arduino IDE into the layout.

    The first program doesn't have to be anything special. To check the correctness of our installation, it is enough to compile and upload an empty, default sketch consisting of a setup and a loop. We can additionally add Serial.print to it to check 100% that the system is working properly. Below is the code for this sample program that we can copy to the Arduino IDE.

    This program will send a welcome string in a loop through the serial port. We can read it using the serial port monitor built into the Arduino IDE.

    Code: c
    Log in, to see the code


    And it's ready! Now you can start using the module with STM32 just like with a regular Arduino.

    Source: https: // www.instructables.com/id/Programming-STM32-Blue-Pill-Via-USB/

    Cool? Ranking DIY
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    ghost666
    Translator, editor
    Offline 
    ghost666 wrote 11809 posts with rating 9944, helped 157 times. Live in city Warszawa. Been with us since 2003 year.
  • #2
    fotomh-s
    Level 24  
    Today the abovementioned the plate (the second, the first I bought on Alla) after 2 months of waiting, price
  • #3
    tmf
    Moderator of Microcontroller designs
    ghost666 wrote:
    Everyone likes Arduino, from the smallest modules on Attiny85 to the largest modules based on MEGA2560 microcontrollers. Unfortunately, they have their limitations - if we need more computing power, higher precision or more analog inputs, we do not have much choice in the Arduino family ... There is, however, an elegant solution that will ensure that we do not have to leave this ecosystem at all.

    The thesis that everyone likes Arduino is risky to say the least :)
    But in terms of content - for years, the Arduino version with ARM has been available - there are versions with Atmelowski SAMD. But somehow they did not gain popularity. Why? Because you can and yes you can upload an arduin bootloader, you can run like the same environment, but most of the so-called "sketches" doesn't work anymore. And here is the problem, because people who are beginners or who are not familiar with microcontrollers can no longer cope with it. So for the same reason other attempts to transplant ARM into Arduino are rather doomed to failure. Anyway, various attempts to let STMs into the world of Arduino have been around for a long time and there are a lot of such tiles. And what? And nothing.
  • #4
    fotomh-s
    Level 24  
    I somehow noticed the popularity of blue pill tiles. In my opinion, a successful design due to the price / performance ratio. As for learning the code, this is my first board for arduino and I had no problem starting and writing the code for the RPN extended programmable calculator. So in general I disagree that beginners in arduino have a problem with that. Previously, I used the Bascom AVR, so the changeover was quite large.
    In fact, I bought the board to build a calculator (the AVRs that I had were not very suitable), now I am thinking about new projects.
  • #5
    khoam
    Level 42  
    tmf wrote:
    Because you can and yes you can upload an arduin bootloader, you can run like the same environment, but most of the so-called "sketches" doesn't work anymore. And here is the problem, because people who are beginners or who are not familiar with microcontrollers can no longer cope with it. So for the same reason other attempts to transplant ARM into Arduino are rather doomed to failure.


    STM32 boards are now very well supported in the PlatformIO environment (Linux / Windows), even better than AVR.
    Arduino HAL also has very good support in PIO, so if someone wants to work a little more seriously with STM32 and Arduino HAL, he should simply avoid the Arduino IDE.

    As for not working of "sketches", it is difficult for me to say, but I work on a daily basis on software that I can compile to AVR, ESP32 or STM32 at the same time, thanks to Arduino HAL and PIO, with minor sections of conditional directives for individual architectures (this is can never be avoided).

    Design STM32duino it's developing quite well and dynamically just like the Arduino HAL for the ESP32. I wish AVR supporters that the development for these processors would also be dynamic, because there has been a stagnation in the support of Arduino HAL for several years.

    Arduino boards with SAMD from the very beginning was probably a minor misunderstanding - price and functionality unacceptable by amateurs / hobbyists compared to STM32 or ESP. Here I can agree that a transplant attempt Atmelian ARMs for Arduino, it's a fiasco.
  • #6
    fotomh-s
    Level 24  
    I believe that STMs are becoming a deeper and deeper nail in the coffin of AVRs when it comes to amateur applications. Generally, the differences are very big when it comes to functionality and attractive prices, which simply outclass AVRs. ZTCP is when it comes to boards with atmel's ARM vs STM ARM, those from ST are probably cheaper if we compare boards with similar capabilities (ZTCP at the price of Arduino DUE, you can have a plate on the M4 core, probably with FPU). In addition, I have already seen Chinese fakes of STMs on Ali (currently as bare chips, I have not seen PCBs with them), they were even cheaper than the original ones (which are already cheap). The Chinese simply slaughtered the AVRs like a piglet ;-)

    As an interesting fact, quartz for RTC is in practice around 38kHz. You can make a stopwatch from it (best if it works without a prescaler, then you can measure very short times), it is connected to a 32-bit counter, so there are no problems with overflow.

    Another interesting feature is the possibility of battery backup of registers, RAM and probably also the RTC. Personally, I have not tested, but the board has a VBAT pin for a backup battery (maybe a supercapacitor).
  • #7
    miszczo997
    Level 28  
    Another interesting fact is that, most likely, the processors assembled by the Chinese in blue piles are not the original processors from STMicroelectronics - stm32f103c8t6, but the coloring of GigaDevice gd32f103c8t6 processors, which are compatible with each other (GigaDevice declares a higher clock speed for its processors). Here is more information on how to recognize which processor we are dealing with https://smdprutser.nl/blog/stm32f103-vs-gd32f103-round-2-blink-a-led/ I haven't tested it myself, but I'm curious if it's true.

    fotomh-s wrote:
    The first is the amount of FLASH memory, declared by the sellers as 64k, in practice it usually has 128k (this is what the bootloader shows).

    Pay attention to the exact processor you have soldered to the board. I saw 2 versions of these tiles:
    1. STM32F103C8T6 - 64kB flash
    2. STM32F103CBT6 - 128kB flash
  • #8
    ghost666
    Translator, editor
    miszczo997 wrote:
    Another interesting fact is that, most likely, the processors assembled by the Chinese in blue piles are not the original processors from STMicroelectronics - stm32f103c8t6, but the coloring of GigaDevice gd32f103c8t6 processors, which are compatible with each other (GigaDevice declares a higher clock speed for its processors). Here is more information on how to recognize which processor we are dealing with https://smdprutser.nl/blog/stm32f103-vs-gd32f103-round-2-blink-a-led/ I haven't tested it myself, but I'm curious if it's true.


    Exactly - I wrote about it some time ago: https://www.elektroda.pl/rtvforum/topic3552273.html Soon we plan to test this system for possible differences.
  • #10
    rb401
    Level 38  
    ghost666 wrote:
    There we add a link to the configuration file for STM32: http://dan.drown.org/stm32duino/package_STM32duino_index.json.


    Here in this topic, ie. STM32 programmed with the Arduino platform, there is some confusion.

    This package, signed by Dan Drown, which must be entered as a preference in the text you translate, is referred to as "unofficial" and is frankly a bit dated. Admittedly, in the case of Blue Pill and Maple, not much has changed. So that will work.

    But three years ago, STM launched its official STM32 package, initially board oriented but eventually supplemented with e.g. Blue Pill, Maple etc.
    Instructions for installing the package with STM:
    https://github.com/stm32duino/wiki/wiki/Getting-Started

    This package with STM has many advantages over the unofficial one. Including probably supports all STM plates (Nucleo, Discovery) from different families, even relatively newer ones, e.g. F7, H7.
    It also has a more efficient code. For example, in the digitalWrite implementation it uses LL library calls (not HAL like the latter). So moving the pins will be very fast here.
    In addition, there is a description of how to manually add any STM32 controller or board to your Arduino.

    But on the other hand, strictly in the light of the topic of loading the program to Blue Pill straight to its USB using the Maple mini bootloader, I'm not sure if it is just as easy as here in this description, although the Maple mini support is there and is there. serial option (although I do not know if it is the factory bootloader or the one from Maple mini).

    Anyway, if someone wants to use STM32 under Arduino, and for example uses STlink or a similar method, I would rather recommend this package with STM.
  • #11
    tronics
    Level 38  
    @ rb401 - I don't know about these packages, but in PIO I had to use older mysensors for compilation because newer ones didn't work (and just spit something out of LL). I remember that for the first time I was compiling in arduino ide and with the Dana package so there is something to do. So within stm32duino there is some incompatibility between versions. But it's easy to manage at PIO.
  • #12
    rb401
    Level 38  
    tronics wrote:
    I had to use the older mysensors to compile because the newer ones didn't work


    It is very possible, because when I took a look at mysensors sources, I can see that there are variant modules for basic hardware functions (e.g. using digitalWrite or digitalWriteFast) depending on the architecture (e.g. AVR, STM32F1) that could be written for specific existing libraries.
    Therefore, something may not be correct, but not in the sense that there is a bug, just a different organizational solution in the libraries. For example, the Dana package was originally only for F1 (and only this one family is actually the mysensors variant) and the STM package supports all families. And it's possible that some conditional fragments in mysensors are incorrectly switched.
    So it is possible that using a different package for STM32, you would need some changes to mysesors, just in this architecture dependent layer.
  • #13
    fotomh-s
    Level 24  
    By the way, someone knows if the OSC32 timer can be stopped, or is it free running like a systick? I am currently using it as a stopwatch. I perform the stop by soft (writes and reads its value from / to the variable). This additional oscillator on the board is a good thing, but does anyone know if it can be replaced with a faster (with higher frequency)? Datasheet says that it should have its own 32.xxxx kHz, but it is probably not stated what will happen if it is faster (the one on the board is in practice closer to 38 than 32 kHz).
  • #14
    szczepan999
    Level 12  
    miszczo997 wrote:
    Another interesting fact is that, most likely, the processors assembled by the Chinese in blue piles are not the original processors from STMicroelectronics - stm32f103c8t6, but the coloring of GigaDevice gd32f103c8t6 processors, which are compatible with each other.


    This explains the low price of these modules.
    I recently ordered 2 pcs from a Chinese, when they come I want to play with it because so far I am only tattooing AVRs.

    Are there any surprises that something doesn't work like the original STM?
  • #15
    fotomh-s
    Level 24  
    I made a programmable calculator on such a Chinese, I have various things programmed there and it works (I still have a lot to add as if that were not enough). I wouldn't expect any surprises, if someone would write about it, after all, these are popular tiles. Surprises are as I wrote, but when it comes to the hardware of the board (bad value of the resistor for USB reported, 2 types of ICs with 64 and 128kB FLASH).

    By the way, it is interesting how many cycles in the Chinese can withstand the FLASH, the datasheet of the original ST states that the bank is over 1000 and 10000 standard.
  • #16
    ghost666
    Translator, editor
    fotomh-s wrote:
    By the way, it is interesting how many cycles in the Chinese can withstand the FLASH, the datasheet of the original ST states that the bank is over 1000 and 10000 standard.


    Among other things, this is what I would like to check - choose a Flash memory area in the MCU and get it ;) .
  • #17
    tronics
    Level 38  
    GigaDevices works on a different principle because it has serial flash and loads the program to the framework after startup ...
  • #18
    fotomh-s
    Level 24  
    How much RAM does it have if it has to divide it into variables and the program?
  • #19
    szczepan999
    Level 12  
    fotomh-s wrote:
    I made a programmable calculator on a Chinese, I have various things programmed there and it works.


    Assuming you didn't do it in arduino - how did you program the board? Stlinek or via bootloader?
  • #20
    fotomh-s
    Level 24  
    I did in ardu on STM32duino. Programmable via UART.
  • #22
    fotomh-s
    Level 24  
    The defeat of the harvest, as they call it, where a few are fighting there, they benefit ... .... The client :-) Goodbye AVRy your time is up ;-)

    Recently, on the channel, a noise reduction like this:
    https://www.youtube.com/watch?v=nNOA2PbIARM&lc=z22nj1dikrqqyrrmbacdp43bqej0yqzensrdl04yusxw03c010c.1552671412982870
    Notice the STM, probably the same as on the blue pill, probably only does a tap delay. Any ATtiny (even the "esoteric" pin-toothed one) would be able to do that.
  • #23
    kamyczek
    Level 38  
    As they say, success has many fathers and failure is an orphan. And this is how many companies try to add ideology to their systems so that it works under ardruino. It is preying on the popularity of the ardruino community for the purpose of popularizing its systems in this case ST. And so many companies do, and for me, when a beggar goes near a market or church, people go there, you have to get something for yourself ...
  • #24
    khoam
    Level 42  
    The Arduino project was never owned by Atmel / Microchip, nor was the project dedicated exclusively to these processors.
    Just read the manifesto: https://www.arduino.cc/en/Main/AboutUs

    Claiming that other processor manufacturers "use" the Arduino brand is nonsensical - Arduino software is Open Source Hardware and any processor manufacturer can participate in this project on an equal footing.
  • #25
    fotomh-s
    Level 24  
    In addition, amateurs of electronics are not very significant buyers compared to the commercial. An amateur buys individual circuits or PCBs with them, while the commercial buys circuits in bundles. Although, by the way, no one defends commercial programming on Arduino, since it is open source ...

    By the way, it seems to me that the tile manufacturers drive this business more than the chip manufacturers themselves, they sell the goods whose recipients are almost exclusively amateurs. As the previous speaker wrote, Arduino is not an IDE created by system manufacturers, and the fact that now there are mainly AVRs and ARMs is a matter of the advantages, popularity and prices of these systems.
  • #26
    tronics
    Level 38  
    Er, AVRy and ARMy? It could have been like that at the beginning, but the Arduino on which the boards were released it received solid support - which means more or less that AVR (without Xmega, tinyAVR 0-series, 1-series and megaAVR 0-series), ARM (Cortexy Atmela, mainly SAMD21), ESP8266. But there is also a stable and good core for other CPUs. The very popular (of the unofficial ones) is the stm32duino mentioned here, but there is also a core for Kinetis (thanks to Teensy - completely unpopular in PL, probably due to the price), SoC mediateka (with wifi), nordic nrf5, lattice fpga (! !), PIC (OLIMEX plates). So whoever produced the "development" tiles for sale was trying to get Arduino support. And even if not, at least give arduino compatible sockets to be able to use shieldy. But for many colleagues, arduino will still be associated just with no debugging, sluggish code for blinking the diode and mindless gluing of the finished products.
  • #27
    Slawek K.
    Level 35  
    tronics wrote:
    Er, AVRy and ARMy? It could have been like that at the beginning, but the Arduino on which the boards were released it received solid support - which means more or less that AVR (without Xmega, tinyAVR 0-series, 1-series and megaAVR 0-series), ARM (Cortexy Atmela, mainly SAMD21), ESP8266. But there is also a stable and good core for other CPUs. The very popular (of the unofficial ones) is the stm32duino mentioned here, but there is also a core for Kinetis (thanks to Teensy - completely unpopular in PL, probably due to the price), SoC mediateka (with wifi), nordic nrf5, lattice fpga (! !), PIC (OLIMEX plates). So whoever produced the "development" tiles for sale was trying to get Arduino support. And even if not, at least give arduino compatible sockets to be able to use shieldy. But for many colleagues, arduino will still be associated just with no debugging, sluggish code for blinking the diode and mindless gluing of the finished products.

    I agree in 100%.

    I have a question, are there these types of STM32 boards with DAC? because from what I can see, the F103C8T6 doesn't have a DAC.

    Greetings
  • #28
    LChucki
    Level 31  
    rs6000 wrote:
    I have a question, are there these types of STM32 boards with DAC? because from what I can see, the F103C8T6 doesn't have a DAC.

    Install yourself STMCUFinder from the STM website, which looks for uC with different options.

    Added after 3 [minutes]:

    fotomh-s wrote:
    Datasheet says that it should have its own 32.xxxx kHz, but it is probably not stated what will happen if it is faster (the one on the board is in practice closer to 38 than 32 kHz).

    Since they wrote max 32 in DS and you give more, it simply will not work or it will work badly. In AVR, e.g. max is 200kHz. If you need faster clocking then connect the generator to some timer input or use the internal oscillator after dividing with a prescaler.
  • #29
    Slawek K.
    Level 35  
    I asked for a board with STM working with Arduino, not bare uC.

    Greetings
  • #30
    LChucki
    Level 31  
    rs6000 wrote:
    I asked for a board with STM working with Arduino, not bare uC.

    Search in NUCLEO tiles by STM.