Repository navigation
Debugging
- The RAK4631 Expansion Board has a 5-pin header for SWD to the nRF52
- Two ideas for an affordable USB-SWD adapter compatible with OpenOCD:
- Notes:
A US$10 clone of an ST-Linkv2 can be found at many online marketplaces.
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.
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.
| 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.
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
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:
The ST-Link can be used in three ways:
- use openOCD to drive it. I find this difficult to use unless I let PlatformIO do all the work.
- re-flash the ST-Link with BlackMagic (BMP) firmware.
- 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
- download: https://www.st.com/en/development-tools/stm32cubeprog.html?dl=redirect
- unzip, install
- run STM32CubeProgrammer.exe
- [Firmware upgrade] button on far right 3/4 of the way down
# 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
> ...