Trying to make friends with STM32

Published on January 02, 2015

Trying to make friends with STM32

    The last time I mocked microcontrollers ATtiny 85, matching the eight-legged poor chips Arduino IDE. And then I wanted to see what kind of miracle it was - the STM32, whose fans look at the AVR programmers (not to mention the arduino) with some disapproval. In the course of a quick googling, it turned out that STM32 "for idiots" exists - there is a Leaf Maple project , in the framework of which there are two boards on the STM32F103 and a development environment that is a clone of the Arduino IDE.

    The decisive factor was the cost. The Chinese version of Leaf Maple Mini sells for $ 4 - a bit more expensive than the Arduino Nano. Having ordered three pieces, I began to wait.

    Perhaps with betting on Maple I was a little hasty - the project is more likely dead than alive. The IDE is not developing, there are no drivers without a tambourine under Windows 8, libraries are in their infancy, complete despondency and desolation. For the sake of interest, I blinked the LED, running the Maple IDE under OS X (it worked out of the box), and then began to think which way to approach the board for further study.

    For starters, I found out this. In the STM32F103CBT6 microcontroller (the names of ST are, I note, severe) on the Leaf Maple Mini board a bootloader that works via USB with the Maple IDE is sewn. It is located in flash memory. And how to program the "bare" STM32? In a good way, you need to use ST-Link, because it allows you not only to “fill in” the firmware, but also to debug it. And without this piece of iron what to do? Use the "system" bootloader STM32, working on UART. There is a mini-board on the CP2102 chip in the bins, you can start to freak out.

    The IDEs that are used to program the STM32 drive me bored. The fact is that I am not a programmer, and multiple windows with tabs and a bunch of scary letters cause a hidden unwillingness to delve into all this. But it seems necessary. The least confused of the trinity (Keil, IAR, Coocox) seemed to me the latter.

    So, the sequence of actions. We put Coocox, to it - the GCC compiler for ARM. We are writing a masterpiece project - Blink. Then on the assembly “board” we assemble the structure from Maple Mini and CP2102. We find out that you need something else to fill in the firmware, because the coconut wants ST-Link. Directly compiled code is easily flashed via UART using the utility from ST - Flash Loader Demonstrator. Now in more detail.

    Coconut with a rake

    I have no rake. The first "ambush" - the current version of the IDE (2.0) - is something strange, suddenly not supporting STM32F1xx. We delete, install version 1.7.7, now we can create a project. We connect the GPIO to the project, take the example with the Blink we need from this module and remodel it a bit to use the Maple Mini LED (PORT B ​​PIN 1). Initializing the ports here is a whole song (understandable, but more complicated than on AVR). That is, you need not just say, they say, this port is the way out. This port - it needs to be turned on and clocked, and it will be an exit with a bow and a bun, and not with a squiggle and a clove ...

    Assembling the iron

    It's simple here - we take the module on CP2102 and connect it to STM32.

    STM - 2102

    RX1 - TX
    TX1 - RX
    GND - GND
    Vin - VCC

    One trick is how to get the STM32F103 to start in UART bootloader mode. The process is well described on the Leaf Labs website in the section "What to do if you mess up the USB bootloader." We connect the BOOT1 leg to the ground, press RESET and the second button, release RESET, release the second button. Hi bootloader!


    It remains to run Flash Loader Demonstrator and “feed” it a bin-file, hanging out after compilation somewhere in the bowels of the project. It is curious what operations are called in this utility. Download is a chip. And Upload is FROM the chip. My perception is rebelling, but maybe it’s so accepted here.


    You can’t just take and blink the LED on the STM32. To do this with two clicks of the mouse (as in Arduino) or a pair of avr-gcc and avrdude commands will not work here. The attempt (Maple IDE) was, but was blown away. Therefore, you have to really sit down and figure out how it works.

    UPD. Added a poll.

    Only registered users can participate in the survey. Please come in.

    Do I need a short article on turning Maple Mini into a ST-Link debugger?