blackmagic-bluepill
blackmagic-bluepill copied to clipboard
Converting a STM32F103 Blue Pill to a Black Magic Probe
Converting a Blue Pill to a Black Magic Probe
This document shows how to convert a STM32F103 Blue Pill to a Black Magic Probe gdb server. A Black Magic Probe (BMP) allows you to download firmware over USB, to set breakpoints, and inspect variables.
A small note: If you have a STM32F103 blue pill, by all means use it. But if you are thinking of buying new, I suggest you buy a STM32F411 Black Pill and install Black Magic Probe for Black Pill. STM32F103 has 128kbyte flash, and after installing BMP flash is 89% full. This is getting tight. STM32F411 "black pill" has 512kbyte flash; this leaves much more room for future features. STM32F411 is a little bit faster, too.
Installing Firmware
Download blackmagic_bluepill.bin. Connect a STM32F103 Blue Pill for serial upload:
- Set boot jumpers for boot from rom: Boot0=1, Boot1=0.
- Connect a USB-Serial adapter with A9 to RX, A10 to TX.
- Press reset.
- Upload the firmware:
stm32flash -w blackmagic_bluepill.bin /dev/ttyUSB0
with /dev/ttyUSB0
the USB-serial adapter
- Set boot jumpers for boot from flash: Boot0=0, Boot1=0.
- Press reset.
- Check the black magic probe shows up on usb:
$ lsusb
Bus 001 Device 044: ID 1d50:6018 OpenMoko, Inc. Black Magic Debug Probe (Application)
Creating Device Files
If you are running linux, download the udev rules for the BMP and install them in
/etc/udev/rules.d/99-blackmagic.rules
:
$ wget https://github.com/blacksphere/blackmagic/raw/master/driver/99-blackmagic.rules
$ sudo cp 99-blackmagic.rules /etc/udev/rules.d/
$ sudo chown root:root /etc/udev/rules.d/99-blackmagic.rules
$ sudo chmod 644 /etc/udev/rules.d/99-blackmagic.rules
$ sudo udevadm control --reload-rules
Disconnect and re-connect the BMP. Check the device shows up in /dev/
:
$ ls -l /dev/ttyBmp*
lrwxrwxrwx 1 root root 7 Mar 24 11:59 /dev/ttyBmpGdb -> ttyACM0
lrwxrwxrwx 1 root root 7 Mar 24 11:59 /dev/ttyBmpTarg -> ttyACM1
Connecting to target
As target system we use another Blue Pill. Connect BMP and target like this:
Black Magic Probe | Target | Comment |
---|---|---|
GND |
GND |
|
PB14 |
SWDIO |
Serial Wire Debugging Data |
PA5 |
SWCLK |
Serial Wire Debugging Clock |
PA10 |
SWO |
Serial Wire Output |
PA3 |
RXD |
Optional serial port |
PA2 |
TXD |
Optional serial port |
3V3 |
3V3 |
Careful! Only connect one power source. |
If Black Magic Probe and target are both Blue Pills, connecting SWD and SWO looks like this:
Connect the Black Magic Probe USB to the Raspberry. Now we are ready to connect to the target system.
$ arm-none-eabi-gdb
(gdb) target extended-remote /dev/ttyBmpGdb
Remote debugging using /dev/ttyBmpGdb
(gdb) monitor swdp
Target voltage: unknown
Available Targets:
No. Att Driver
1 STM32F1 medium density M3/M4
(gdb) attach 1
See the overview of useful gdb commands for an introduction to using the BMP.
stm32duino
If you are using the Arduino IDE with the stm32duino arm processor add-on:
In the Arduino IDE, choose Tools->Upload Method-> BMP (Black Magic Probe) to upload firmware using the BMP. This uploads the firmware using the arm-none-eabi-gdb
command. The command line options to arm-none-eabi-gdb
are in the tools.bmp_upload section of ~/.arduino15/packages/STMicroelectronics/hardware/stm32/2.0.0/platform.txt
When debugging arm processors, there are three ways for the target to print debug messages on the host: Semihosting, Serial Wire Output SWO, and Real-Time Transfer RTT. There are three Arduino libraries that may be useful:
See also
See the overview of useful gdb commands for an introduction to using the BMP.
If you want more in-depth information, read the Black Magic Probe Book.
not truncated