Using a STM32F4Discovery board to flash STM32F100RB from STM32VLDiscovery

Almost 2 years ago I replaced the ST-Link firmware of STM32VLDiscovery to become a Versalon programmer.

It worked fine to program some boards, but today it didn’t work to program the STM32F100RB target chip from itself STM32VLDiscovery. I ported NuttX to run on STM32VLDiscover, but was facing many issues to store the final nuttx.bin firmware inside STM32F100RB.

I just realized I have a STM32F4Discovery board (with its built-in STLink-v2) which is supported by OpenOCD, then I decided to test the idea of using STLink-v2 to flash STM32F100RB directly.

It was easy, just removed the 0R resistors from SB11, SB17, SB18 and soldered some wires from STM32F4Discovery’s CN2 to these SBx pins (bottom side of SB11 and left side of SB17 and SB18. Also I need to solder connect the GND pins of both boards.

The STM32F4Discovery’s CN2 pinout is presented in this post.

You need to open a terminal and execute:

# openocd -f interface/stlink-v2.cfg -f target/stm32f1x_stlink.cfg

Open On-Chip Debugger 0.8.0-dev-00291-g624e74e (2013-12-29-15:30)
Licensed under GNU GPL v2
For bug reports, read
Info : This adapter doesn't support configurable speed
Info : STLINK v2 JTAG v17 API v2 SWIM v0 VID 0x0483 PID 0x3748
Info : using stlink api v2
Info : Target voltage: 2.912456
Info : stm32f1x.cpu: hardware has 6 breakpoints, 4 watchpoints

Then open other terminal, make sure the your nuttx.bin is in the same directory you are, and execute these commands:

$ telnet 4444
Connected to
Escape character is '^]'.
Open On-Chip Debugger

> reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x0800015c msp: 0x20000cfc

> flash probe 0
device id = 0x10016420
flash size = 128kbytes
device id = 0x10016420
flash size = 128kbytes
flash 'stm32f1x' found at 0x08000000

> stm32f1x mass_erase 0
stm32x mass erase complete

> flash write_image nuttx.bin 0x08000000 
target state: halted
target halted due to breakpoint, current mode: Thread 
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000cfc
wrote 78128 bytes from file nuttx.bin in 2.361482s (32.309 KiB/s)

> reset run

Easy, right?

Update: new version of OpenOCD (i.e. 0.8.0) doesn’t work with above commands. Then you need to return to old version:

$ git checkout 215c41c0174e94ab00b36a7d56a054cdd7f30dd0