Krishna Boopathy

BLACK MAGIC PROBE on STLink v2

Intro:
Usually an embedded developer stays loyal to one brand of microcontrollers/microprocessors as this is relevantly easy to maintain one set of debugging tools and development environment for all target devices. This vastly restricted me in exploring other vendors and I stayed with the ST for the availability of the cheap development boards.

Recently I was searching for a good all round debugger that I can use with every common MCUs and obviously the easy choice was the SEGGERS. But the problem is the huge cost that comes with it. And I dont have good reviews with clones.

Thats when I cam across BMP..!!

Technical Details:
The Black Magic Probe (shortly BMP) is an open source debugger device that can be used to flash and debug various ARM Cortex-M cores over the CMSIS-DAP through the Single Wire Debug(SWD) protocol.

I have personally tested and found it great with STM32F10x and PIC32CMJH devices. What really sets this debugger apart from other players is that it directly runs the GDB server and so no openOCD is required.

Also the debugger device can be bought online. But for the engineers ;-), you can build the firmware yourself for a variety of third party debuggers. For ex: You can convert a cheap STLink clone into the black magic probe.

Pre-Requisite:
I will be explaining the steps that I followed to convert my STLink v2 into a black magic probe.

  1. We need two STLinks here. Since they are dirt cheaps I have couple of those buggers lying around.

  2. In one of the STLinks that you intend to convert it to BMP, open the case and identify the SWCLK, SWDIO, Vcc and Gnd pins for the chip present.

  3. Hook up the secondary STLink to the first debugger.

  4. Now clone the black magic repo into any of your directory structure. I use debian by the way. For Windows/MAC users refer to the BMP official page for detailed steps.

  5. Install the dependencies like git, meson and ninja.

  6. Install the arm GCC toolchain and update the $PATH

  7. Navigate to path_to_blackmagic/src/platforms/README.md to see list of all supported hardwares. Here I will be using the stlink. Depending on your hardware you will change the input parameter in the argument PROBE_HOST given in the next step.

  8. Navigate to path_to_blackmagic/ and give the following command make PROBE_HOST=stlink

  9. Now the following binaries are generated inside the location path_to_blackmagic/src/

  1. Initially flash the blackmagic_dfu.bin at location 0x8000000 using STMCubeProg which is hassle free. If it says the FLASH memory can't be read or similar error simply change the Read Out Protection in the OB tab. Consider this DFU as more like a USB bootloader if you are not familiar with DFU.

  2. After successfully flashing the blackmagic_dfu.bin, remove the USB cable from the STLink.

  3. Now directly connect your STLink that you wish to convert to BMP into your PC. This now has a USB bootloader(DFU) with which you can now flash the blackmagic firmware.

  4. Now execute the following command. sudo dfu-util -d 1d50:6018,:6017 -s 0x08002000:leave -D blackmagic-native.bin

The 1d50 and 6018 are PID and VID of the STLink device. You make sure you are populating this field correctly.

  1. Once this is flashed, you remove the USB plug and connect again. If you are successful till here you will find two new devices /dev/ttyACM0 and /dev/ttyACM1

  2. Congratulations. You have achieved the Black Magic Probe (BMP).

How to debug using BMP:
Follow the next post.

Please do get in touch if in case you need more clarity. Thanks.

#projects