Electronic – Programming a new STM32 chip

microcontrollerst-linkstm32stm32f10xswd

I am new to STM32 and recently trying to make a custom board with STM32F103RB. But I am a bit confused by the available methods to program the chip. Let's say I use ST-Link via SWD, does it mean that I do not need to burn bootloader to the chip on my own? That is, does it mean that I can program the brand new chip directly with ST-Link without any other additional procedure?

If yes, then does it mean that I do not need to use BOOT0 and BOOT1 pins?

What about using USB via USBDP and USBDM pins on STM32?

Thank you all very much!

Best Answer

The bootloader is in ROM, it is not user-modifiable (ie: you can't "burn" a new bootloader). This appnote describes the bootloader features for different STM32 parts.

On the all the STM32 parts that I've used, you pull BOOT0 to ground to bypass the bootloader and boot from flash (address 0x0800000 on most STM32s). With BOOT0 pulled low, the pin state of BOOT1 doesn't matter. I normally pull BOOT0 down with a 100 kOhm resistor on the boards I design at work. Don't leave it floating, it is not pulled down internally so funny stuff will happen if you don't pull it down.

You can use ST-Link SWD to flash your firmware to the chip and debug running code. Any IDE that supports the STM32 should know how to do this out of the box, I personally use Ac6 because it's free. As a minimum, you need to connect the SWDIO, SWCLK, and GND lines to the programmer, but you should also bring out NRST wherever possible because debugging without a hardware reset line can be a real pain.

As for your last question - the bootloader for the F103 series does not support USB, although some other parts (like the F105 series) do. I would not recommend programming via USB unless you have a specific reason to: SWD will let you program and debug, and is vastly simpler to get working.