Preparing for serial re-flashing Mar 2016
The STM32F103 µC chips all have a ROM-based boot loader on board. Most chips variants can only be re-flashed via USART1, using the PA9 and PA10 pins, so we will need to connect to that serial port initially - even if the board is intended to be used only over USB or RF later on!
This is the “Blue Pill” board which will be used in this example:
Boards like these are very common, low-cost, and easy to find (on eBay, for example).
STM32F103xx chip variants can be used, as long as they have at
least 64 KB flash and 20 KB RAM. Most of the low-cost boards contain a 48-pin
C8 (64K flash) or
CB (128K) chip. The
RB chips have 64 pins. If
the chip is an
xC, it has 256K flash and 48K RAM, and if it’s an
512K flash with 64K RAM. The
Vx chips are 100-pin and the
Zx’s even have a
144 pins. And then there’s the small
board - marked
TB, with 128K flash and 36 pins.
So much for picking a board - as you can see, there are many candidates!
The serial connection can be very simple, all we need is power, ground, and the transmit plus receive signals. The Arduino-style DTR/RESET and CTS/RTS signals are not used here:
Four wires need to be connected as follows (you could also use jumpers or a breadboard):
(ignore the wires on the left, these are for the radio - they are not needed at this point)
A note on “RX” and “TX”: these are named from the perspective of the FTDI board i.e. header pin RX receives data sent out from pin PA9, which is therefore called TX on the µC’s USART1 - and similarly, header pin “TX” connects to PA10, which is USART1’s RX. It’s all crossed over.
Power to the board should be 5V, and be fed to the on-board regulator, not directly to the STM32F103 chip - applying 5V directly to the µC chip will damage it. The RX/TX signal levels should be 3.3V, but this will work with 5V on PA9/PA10 (not all pins are “five volt tolerant”!).
The last thing to note about connections is that the STM32F103 µC needs to be placed in a special “boot mode” to erase and re-flash its memory. On the above board, there are two jumpers for this, one for BOOT0 and one for BOOT1 (which rarely needs to be changed, if ever).
Here is how to place this board in boot mode, by lowering BOOT0 on the right to logic “1”:
Now insert USB + board to power up again.
Perfect, we’re all set for the next step: uploading the firmware - stay tuned…
(don’t forget to put this jumper back and press reset again once the firmware upload is done)