Introduction

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”.

bmpm_V2_1c_nocap_iso_1024x1024

Pre-requisites

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)

Note: If you dont have a STLink, you could follow another How-to which use a USB to Serial converter [1] or if you have a useless STLink clone, this one could be reflashed as a Black Magic Probe [2]

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.

Wiring

No mystery here, we have to use the four pins availables (SWD + 3V3 + GND) on the Blue pill, and connect it to the STLink.

bluepill_converted_to_magic_prob

Flashing

Open STLink utility, click on “Connect to the target” in order to see if the STLink is recognized and could access to STM32F103 memory.

stlink_stm32f103_connection

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).

stlink_flash_blackmagic_dfu

Same thing for blackmagic.bin but the start address is 0x08002000.

stlink_flash_blackmagic

Test (Smoky!)

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.

bpm_peripheral_manager

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.

References

Acknowledgments to Black Magic team and peoples who are sharing their knowledges.