Blackmagic probe revisited

Turn Your $2 STLink Clone Into a Black Magic Probe

TLDR: Transform that cheap STLink V2 clone into a proper debugger by flashing Black Magic Probe firmware. 15 minutes of work, intermediate difficulty, and a surprisingly good outcome for something that probably came in a plastic bag with no labels.

Historical Context

Back in 2016, I wrote about installing Black Magic Probe on STLink clones. My main contribution was discovering the correct SWD/SWIM pinout through systematic testing (or as I like to call it, “guided pin juggling”) – since every Chinese clone seems to have its own creative interpretation of pin assignments.

Since then, the Black Magic Probe project has evolved significantly – moving from Make to Meson build system. This guide covers the current (2024) method.

What You’re Getting

Black Magic Probe (BMP) provides direct GDB support without needing OpenOCD or other middleware. It’s perfect for STM32 development and transforms your basic STLink clone into a full-featured debugging tool.

Prerequisites

  • STLink V2 clone (tested on Baite)
  • Linux/macOS (Windows users: use WSL)
  • Required tools: – git – meson & ninja – arm-none-eabi-gcc – st-flash – dfu-util

Part 1: Build & Flash Bootloader

The bootloader (8KB) manages firmware updates. It must be flashed first to the correct address.

# Clean start
rm -rf build

# Configure and build bootloader
meson setup build --cross-file cross-file/arm-none-eabi.ini \
    --cross-file cross-file/stlink.ini -Dprobe=stlink \
    -Dbmd_bootloader=true -Dtargets=stm -Drtt_support=false
ninja -C build boot-bin boot-elf

# Flash bootloader to address 0x08000000
st-flash erase
st-flash write build/blackmagic_stlink_bootloader.bin 0x8000000

Part 2: Build & Flash Main Firmware

Critical: Use DFU for the main firmware, not st-flash. Your device should now appear as a DFU device after the bootloader flash.

# Build main firmware
meson setup build --cross-file cross-file/arm-none-eabi.ini \
    --cross-file cross-file/stlink.ini -Dprobe=stlink \
    -Dbmd_bootloader=true -Dtargets=stm -Drtt_support=false
ninja -C build -j$(nproc)

# Flash firmware to address 0x08002000 using DFU
dfu-util -a 0 -s 0x08002000:leave -D build/blackmagic_stlink_firmware.bin

Verification

  • Two new serial ports should appear: – /dev/ttyACM0: GDB server – /dev/ttyACM1: UART console
  • Test with: blackmagic -t
  • Connect in GDB: target extended-remote /dev/ttyACM0

Troubleshooting

  • No DFU device after bootloader: Retry flashing bootloader
  • DFU error during firmware flash: Unplug/replug device
  • No serial ports appear: Repeat firmware flashing
  • Permission errors: Add appropriate udev rules

Why This Order Matters

The memory layout is split into bootloader (0x08000000) and main firmware (0x08002000) regions. The bootloader must be installed first as it manages future firmware updates. Using st-flash after bootloader installation can overwrite critical memory regions – that’s why we switch to DFU for the main firmware. Yes, we could also think long and hard and flash it correctly. This way it was easier. I also failed to flash the correct memory layout before.

Conclusion

With Black Magic Probe firmware, your STLink clone becomes a capable debugging tool with direct GDB support. Consider setting up udev rules and exploring ARM debugging with GDB for your next project.