I was lookin for a cheap solution to debug SAMD21 microcontroller as they are more and more popular (next generation of Arduino boards), and as STM32 are pretty rare those times. I found a project called Black Magic Probe, which offer debugging capacity for all kind of ARM chips via SWD or JTAG (+ virtual COM port), but the probe is difficult to find in a webshop nowadays and in the same price range than the famous J-Link EDU probe (~60€ on RS/Farnell). Main advantage of this probe is that this one is open source, maintained, and can be flashed on a cheap "Blue pill" (~5€) even if you have clone.
In the next steps i will explain how you can flash a Blue Pill in order to obtain a "BMP".
Here is what you will need in order to turn the Blue pill into a Black Magic Probe:
- Blue pill (or a red/black one) with a STM32F103C8T6
- STLink v2 (cheap clones are availables on eBay or Aliexpress)
- Jumper wires Female/Female (x4)
For the software part you will need the two binary files attached below:
Note: even if it's not the latest version available it could be updated later via dfu.
TODO: explain how to get/build latest version.
No mystery here, we have to use the four pins availables (SWD + 3V3 + GND) on the Blue pill, and connect it to the STLink.
Open STLink utility, click on "Connect to the target" in order to see if the STLink is recognized and could access to STM32F103 memory.
Next, go to "Target", "Program...", select the binary blakcmagic_dfu.bin, set the start address 0x08000000 and click on Start (after the flashing, a reset occur and LED on Blue pill should blink).
Same thing for blackmagic.bin but the start address is 0x08002000.
Once done, remove jumper wires and plug the blue pill to the computer (via the micro USB port), the board will be recognized as a Black Magic Probe 1.6X.
If you look at the peripheral manager, two devices should appear.
Well done, and thanks to the Black Magic Probe authors, now you can use your Blue pill in order to debug almost any ARM chips. SWD pins are the same than the ones used in order to flash it. JTAG is available on PA13 (JTMS), PA14 (JTCK), PA15 (JTDI) and PB3 (JTDO), see this readme.md for more details.
A next post will explain how to use this Black Magic Probe with Visual Studio code (and the well known Platform.io extension) on a SAMD21.
Acknowledgments to Black Magic team and peoples who are sharing their knowledges.
 blackmagic Public - In application debugger for ARM Cortex microcontrollers.
 Converting an STM32F103 board to a Black Magic Probe.
 JeeLabs - Black Magic Probe.
 Black magic probe out of cheap STLink programmers (nice pics!).
 JTAG/SWD debugging via Black Magic Probe on an STM32 blue pill.