Skip to content

Debugging

!!Dean edited this page May 10, 2026 · 10 revisions

Preliminary info

Bootstrap programmer

A US$10 clone of an ST-Linkv2 can be found at many online marketplaces.

BMP on Blackpill

Context

Using a stm32f411ce "blackpill" board, you can make an effective gdb remote for embedded targets using Black Magic Debug Software.

The prebuilt software for this board is linked below. For steps to build this firmware yourself, see the 'Build BlackMagic on Windows11' section and use 'cross-file/blackpill-f411ce.ini' for the cross-file argument.

Download Bootloader

Download Firmware

Flash Black Magic Debug to the Blackpill:

In order to flash the bootloader, use a AITRIP ST-Link V2 Emulator or similar ST-Link emulator connected to the debug headers of the blackpill with pins SWCLK, SWDIO, 3.3v, and GND. Next we must install STM32CubeProgrammer (see 'Update ST-Link Firmware' for installation steps). With your ST-link device plugged into your development machine, and the blackpill connected with debug headers, run the following commands:

.\STM32_Programmer_CLI.exe -c port=SWD freq=4000 mode=NORMAL -w "Path\to\blackmagic_blackpill_f411ce_bootloader.bin" 0x08000000 -v -rst
.\STM32_Programmer_CLI.exe -c port=SWD freq=4000 mode=NORMAL -w "Path\to\blackmagic_blackpill_f411ce_firmware.bin" 0x08004000 -v -rst

Once completed sucessfully, the blackpill should have a static blue light lit.

Now plugging in the blackpill to your development machine with USB should result in 2 USB COM devices being detected. From a terminal run:

arm-none-eabi-gdb
target extended-remote ## OS dependant COM port syntax ##

The OS dependant COM port syntax refers to selecting one of the two COM ports associated with the blackpill. On windows this looks like \.\COM6 for example. Pick the COM port that does not give "time out" errors.

Now you should be able to run monitor version from the gdb interface to fully verify the blackpill accepted the black magic software.

Debug/Programming Connection between the nRF52 and the Blackpill:

STM32 Pin Blackpill Pin Signal RAK4630 Pin nRF52840 Pin
Any GND 23 GND 4 Any VSS
Any VDD 22 POWER 1 Any VDD
PA5 15 RESET 5 nRESET
PB8 45 SWCLK 3 SWDCLK
PB9 46 SWDIO 2 SWDIO

*POWER: DO NOT connect the POWER between the two boards if the nRF52840 is also getting power from its USB. Only connect POWER if the Blackpill is powered by its USB and the nRF52840 has no other power supply.

BlackPill RAK4630 Single Wire Debug (SWD) connection diagram

Debugging the NRF52 with the Blackpill:

Run:

arm-none-eabi-gdb ## path to current .elf for bin on nrf ##
target extended-remote ## OS dependant COM port syntax ##
monitor connect_rst disable
monitor swd_scan

You should see scan results that look like:

Available Targets:
NO. Att Driver
 1      nRF52 M4
 2      nRF52 Access Port

Then lastly attach to the device number associated with the M4. For the output above this would be:

attach 1

ST-Link

I have an old Nucleo board with a built-in ST-Link. REMOVE BOTH JUMPERS from CN2 so that the CN4 header can do SWD to off-board targets. Here's the pinout:

ceaddead685e6219f5c5d5c8eb57979991978816

The ST-Link can be used in three ways:

  1. use openOCD to drive it. I find this difficult to use unless I let PlatformIO do all the work.
  2. re-flash the ST-Link with BlackMagic (BMP) firmware.
  3. Use the ST-Link with up-to-date firmware with the BlackMagic desktop app.

The rest of this section explains how to do #3. Here's background info: https://github.com/blackmagic-debug/blackmagic/blob/main/src/platforms/stlink/README.md

Update ST-Link Firmware

Build BlackMagic on Windows11 (for ST-Link and Desktop)

# Install meson and ninja build tools
> python3 -m pip instlal meson
> winget install Ninja-build.Ninja

> git clone https://github.com/blackmagic-debug/blackmagic.git
> cd blackmagic
blackmagic> meson setup build --cross-file cross-file\stlink.ini
blackmagic> meson compile -C build
blackmagic> dir build

> ...
> 12/18/2025  22:24         2,640,571 blackmagic.exe
> 12/18/2025  22:24           113,252 blackmagic_stlink_firmware.bin
> 12/18/2025  22:24         1,159,496 blackmagic_stlink_firmware.elf
> ...