May 22 2017

How to convert an STM32F103C8T6 into a Black Magic Probe

There are several tutorials on the internet showing how to convert an STM32F103C8T6 into a Black Magic Probe. Unfortunately, none of them worked for me. So, I decided to write this post in case others run into the same problem as I did. The problem I ran into was the memory size of the STM32F103C8T6 chip I am using. It reports that it only has 64K of flash. The Black Magic Probe software is a bit larger than 64K so the utilities report there is not enough memory and stop.  Decoding ‘STM32F103C8T6’

 

STM32F103C8T6
STM STMicroelectronics – Vendor
32 32-bit, ARM series
F103 model, ‘F1’ = ARM Cortex M3
C 48-pins
8 64 KB flash memory
T LQFP package type
6 temperature range -40..+85 °C

 

we see that it is only supposed to have 64K, however, it probably has 128K. Mine does!  So, with a bit of ‘trickery’, we can make it work.

There are possibly three different ways to connect and interface with the STM32F103C8T6 board:

  1. Serial port
  2. USB
  3. JTAG / SWD

The utility software (listed below) varies as to what interface it uses. To get my STM32F103C8T6 module to work with the utility I need, I used an ST-LINK programmer which attaches to the SWDCLK/SWDIO/PWR/GND pins.

How to convert an STM32F103C8T6 into a Black Magic Probe Here is a list and some information about the software tools (utilities) you will run across when reading articles about programming the STM32F03C8T6. Incidentally,  I run a Linux distribution called ‘Fedora‘. If you are running a different Linux distribution, you will need to run your appropriate package installer rather than the one (dnf) Fedora uses.

For installing and compiling some of these utilites, you will need git, cmake and the ‘normal’ set of development tools installed. If you do any development work these tools should already be installed.

Here is the command to install all the needed development (C compiler) tools for the ARM processor:

Many of the useful utilities are coded in Python and need the Python serial module. Here is how to install it:

Here is a list of the utilities:

stm32flash
Open source cross platform flash program for the STM32 ARM microcontrollers using the built-in ST serial bootloader over UART or I2C

stm32loader.py
Python script which talks to the STM32 bootloader (via the serial port) to upload and download firmware.

stlink
Open source version of the STMicroelectronics Stlink Tools

dfu-util
DFU is intended to download and upload firmware to/from devices connected over USB.

OpenOCD
Open On-Chip Debugger

Black Magic Probe
In-application debugging tool for embedded microprocessors.

I eventually installed all of these utilities, however to create a “Black Magic Probe Clone” I really only needed stlink, OpenOCD and the Black Magic Probe software. So, here is how to convert an STM32F103C8T6 into a Black Magic Probe:

I installed OpenOCD via:

This step (using OpenOCD to unlock the code protection of the board that will become your new Black Magic Probe) may not be needed but just in case, here it is:

Next, I installed the stlink utilities globally via:

Then, to create the Black Magic Probe Software:

Make sure you are in the black magic probe src directory. Then erase memory and flash the black magic DFU and software ‘bin’ files via:

Note: Here is where the ‘trickery’ comes in. Using the parameter –flash=0x20000 we can override the reported 64K and specify 128K. Now you can unplug the STLINK programmer and plug in the usb port. You should then see two enumerated ports (probably /dev/ttyACM0 and /dev/ttyACM1).

To make it easier, next time I wanted to do this, I created a Python script which runs those needed commands. Additionally, it combines blackmagic_dfu.bin and blackmagic.bin into one bin file called bmp.bin. The script allso runs stlink to dump the memory (after flashing) to compare it with the original to make sure the flash worked ok.

Here is the Python script (it needs to run from the blackmagic probe src directory):

If you don’t have an STLINK programmer, there is an alternate method to create and flash the bmp.bin file. Create the bmp.bin file with this Python script:

STM32FLASH can be used with a USB to serial converter to flash the bmp.bin file via the following command:

Make sure to replace the /dev/ttyUSB0 with your specific port.

To test your new ‘Black Magic Probe clone’, attach it to a target:

STM32F103C8T6 as a BlackMagic ProbeThen run:

Leave a Reply

Your email address will not be published.