Flashing Blue Pill using ST-LINK V2 (Clone?) / fixing flash: 0
Programming the Blue Pill using ST-LINK V2
The STM32F103 “Blue Pill” board is an inexpensive STM32F103 based microcontroller.
I’ve previously flashed a USB bootloader to the Blue Pill using a Raspberry Pi. The Blue pill’s USB connector is
The ST-LINK V2 programmer provides a more reliable way to flash the Blue Pill boards in addition to debugging capabilities.
Connecting the Blue Pill to the STM-32
ST-LINK V2 | Blue Pill |
---|---|
PIN 2 SWCLK | SWCLK |
PIN 4 SWDIO | SWDIO |
PIN 6 GND | GND |
PIN 8 3.3V | 3.3V |
Jumper positions
When programming with ST link, it’s not necessary to move the jumpers on the Blue Pill board.
Install Stlink on macOS
brew install stlink
st-info --probe
Found 1 stlink programmers
serial: 533f6b064975524918500267
openocd: "\x53\x3f\x6b\x06\x49\x75\x52\x49\x18\x50\x02\x67"
flash: 65536 (pagesize: 1024)
sram: 20480
chipid: 0x0410
descr: F1 Medium-density device
Unlock flash (if necessary)
When I ran st-info --probe
, one of my Blue Pill boards reported reported flash: 0
This was fixed by unlocking the flash using OpenOCD.
Install OpenOCD and telnet
brew install openocd
brew install telenet
Run OpenOCD:
In one terminal:
sudo /usr/local/bin/openocd -f /usr/local/share/openocd/scripts/interface/stlink-v2.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg
Leave OpenOCD running and proceed to the next step.
Connect with telenet
In a second terminal:
telnet localhost 4444
Connected to localhost.
Escape character is '^]'.
Open On-Chip Debugger
flash probe 0
device id = 0x20036410
STM32 flash size failed, probe inaccurate - assuming 128k flash
flash size = 128kbytes
flash 'stm32f1x' found at 0x08000000
stm32f1x unlock 0
device id = 0x20036410
STM32 flash size failed, probe inaccurate - assuming 128k flash
flash size = 128kbytes
Device Security Bit Set
stm32f1x.cpu: target state: halted
target halted due to breakpoint, current mode: Thread
xPSR: 0x61000000 pc: 0x2000003a msp: 0x20000400
stm32x unlocked.
INFO: a reset or power cycle is required for the new settings to take effect.
Programming with st-flash
st-flash --reset write /var/folders/lp/wpsytg2x2mq5qqjjlqm67j1r0000gn/T/arduino_build_430953/sketch_mar23a.ino.bin 0x08000000
Links
stlink issue “Reports 0K of Flash with STM32F205VG”
CLion for Embedded Development Part II
Flashing Bootloaer for Blue Pill boards
STM32F103 Bluepill–Getting Started with Arduino core