The Black Magic Probe (BMP) is a great debugging tool for ARM Cortex µCs. This is a description of how to create one using a low-cost “Blue Pill” board.
The BMP can upload firmware to a wide range of µCs over JTAG or SWD, as
well as connect to a serial port for simple communication. It also supports
gdb debugging, e.g. single-stepping, breakpoints, and examining memory.
The BMP is supported by PlatformIo, my go-to tool for all embedded µC development (see example at end): BMP + PIO = an amazing combo!
Here is a target Blue Pill (left), being prepared for use with a BMP (right):
This simple 4-pin female header “adapter” allows uploads and debugging. For serial, 6 pins are needed. For RESET / SWO, 2 more pins must be connected.
The 8-pin header layout is compatible with the 6-pin header on a “HyTiny” board, another low-cost STM32F103 board (from Haoyu):
It’s a somewhat arbitrary choice, but as good as any - most boards differ in their pin choices anyway. One solution will be described further down below.
There is no 5V power on the header, to avoid accidental damage. Only 3.3V, with limited current capability (around 50 mA). Boards which need more current or other voltages have to be powered in other ways.
The problem with turning a Blue Pill (BP) into a Black Magic Probe (BMP) is that there’s no convenient way to program that BP until you have a BMP! The solution chosen here, is to get an (equally cheap) “ST-Link” clone, which has far less functionality than a BMP but makes a very useful fallback option:
If all else fails, that ST-Link can also help restore a broken or damaged BMP.
Here are the steps needed to reach that magical setup which the BMP offers:
And for completeness, since BMP’s µC support continues to evolve:
The stlink utility by user “texane” on GitHub, is an open source tool for STM’s “ST-Link” hardware, of which there are several generations by now.
ST-Link V2 is based on the common STM32F103 µC and has been widely cloned for quite some time now. It’s very easy to find “ST-Link sticks” on eBay and on Chinese sites (they all come from China anyway).
Unfortunately, these ST-Links don’t expose their serial port UART pins, so they can’t be turned into a BMP without losing some of its most useful features. But they can be used to re-program a Blue Pill, which is the next best option.
See the README for Win/Mac/Linux installation instructions. It’s very easy.
There are two approaches to getting the BMP firmware: lazy and long-term. The lazy option is to download the build files I’ve collected here: