Convert stlink to bmp - grumat/glossy-msp430 GitHub Wiki

Converting a Clone ST-Link to BMP


This MOD is unrelated to the Glossy-MSP430 hardware project.


Note that this procedure does not use the original STLink bootloader and you should not follow these instructions on a legitimate board, because your original license key will be erase and you will not be able to revert it back to the original STLink as it once was.
The blackmagic site has proper instructions that apply to an original board, preserving the original bootloader.

Summary of this Modding Guide

Applies to: STLinkV2 fake/clones using the same plastic case sold by ST.

Goal 1: Add a VCP port to the original circuit.

Goal 2: Install the Black Magic Probe firmware into these clones.

Constraint: The SWIM functionality will be deactivated.

Additional Advantage: The MOD is also compatible to STLinkV2+VCP variant, by installing the proper firmware.

Introduction

Since I am buying those hardware pieces from China's web stores just to reuse the plastic case, I am accumulating lots of original PCBs, which we can reuse for ARM development.

Instead of the standard ST-Link V2 functionality provided with those generic clones, we just want to convert them to ST-Link V2-1 by adding the VCP feature.
For sure, the firmware that I want to install is the Black Magic Probe, as it is uncomplicated to work with GDB, since we can dismiss the Man on the Middle software such as OpenOCD oder similar stuff, while keeping project requirements only to open source stuff.

For this operation you will need another STLink unit (JLink or similar is also an option).

When disassembling a generic ST-Link clone, you will ge something like this:

stlink-overview-fs8.png

Note how chinese are hypocritical: The MCU has its code erased. Strange how a theft that steals case form, logotype and firmware wants to protect this very rough hardware implementation of the original product by erasing the soldered MCU model markings. No ESD protection on USB and JTAG bus is provided; no impedance matching resistors either.
While original design can be found on ST website...

Patches

The picture below shows the modifications required to convert yor STLink V2 Clone into a STLink V2-1:

stlink-patches-fs8.png

Perform following steps:

  • Cut 4 tracks responsible for the SWIM interface, as marked in yellow on the picture;
  • Remove R13 and R17, also part of the SWIM interface;
  • Solder two wires as illustrated in blue and purple lines; Note that it is recommended to solder at the right side of the resistor R15/R16, so that they are used in series with the connection line, which helps with impedance matching when connecting this line to a high impedance input.

This is a picture of the modified board:

stlink-patched-fs8.png

Please take care to leave the space around the white connector free, because of the form of the plastic shell. The wire that is soldered to R16 needs to keep enough distance of the white connector, so in this example, it follows a straight line from the MCU pin up to the resistor, detailed on this picture:

stlink-patch-zoom-fs8.png

Internal SWD Pinout of these boards

The picture below shows the pinout of the chinese clone (which, by the way, matches that of the original version):

stlink-pinout-fs8.png

The J2 provides access to the SWD bus and I marked each function with yellow labels on the picture.
You can use a regular SWD programmer to install a new firmware onto that board, using this connector.

The blue labels marks the serial port functions after the MOD is applied.

Building the firmware

Steps for Windows OS

A rough step by step is performed the following way:

Create an Ubuntu installation in WSL and install development stuff (packages build-essential, crossbuild-essential-armel, gcc-arm-none-eabi, ...).

Steps to build a BMP firmware (as already stated before, this is not compatible with the original STLink bootloader, which uses another memory mapping):

git clone https://github.com/blackmagic-debug/blackmagic.git
cd ~/blackmagic/
make PROBE_HOST=stlink

Produced firmware files are ~/blackmagic/src/blackmagic_dfu.bin and ~/blackmagic/src/blackmagic.bin

Optionally, you can compile a stable version if you type something like this:

cd ~/blackmagic/
git checkout v1.8.2
make PROBE_HOST=stlink

Writing the Compiled Firmware

Now using Windows and a second STLink (using ST firmware), write the blackmagic_dfu.bin into 0x08000000 using the STM32CubeProgrammer. Please check the pin-out as shown on a previous picture.

For this step, pay attention on the following points:

  • Use Female to Male header cables. You can insert the male pin into the connector following the connection scheme showed on the picture above:

    • GND cable to the GND pad
    • SWCLK cable to the CLK pad
    • SWDIO cable to the DIO pad.
    • Do not connect Vcc. Typically the installed LDO of chinese clones cannot cope with the load of a second board and is very common that connection cannot be established.
      • If you are using ST-Link or original STLink V2, you need to connect this signal to the pin 1 of the 20-pin JTAG connector.
      • If you are using another STLink V2 clone, this wire is simply not required.

    Tip: Use a soft rubber to hold the jumper wires. Just insert the pins into the pads and perforate the rubber while holding it in the back of the J2 holes.

  • After all jumper cables are reliably connected, connect the both tools using proper USB cables.

Now that both boards have power supply proceed with the Flash operation:

  • Erase flash
  • You will possibly need to clear the Read Protection flag of the target STLink board.
  • Select the blackmagic_dfu.bin file and ensure that write address is 0x08000000.
  • Click the flash button.
  • After finish, disconnect and turn everything off.

Now reconnect the target STLink. It will enter DFU since it has no firmware.

Download a copy of the open source dfu tool. I recommend downloading the dfu-util-0.9-win64 version, because newer versions strictly enforce file contents and you may get into trouble to figure out how to proceed.

Using an Admin Command Prompt, cd to the directory where dfu-util were extracted and type:

dfu-util-static.exe -d 1d50:6018,:6017 -s 0x08002000:leave -D \path\to\blackmagic.bin

This will install the BMP firmware. Reconnect modified STLink to start using it. Note that in the future, only the last step is required when upgrading the firmware to a newer version.

A full featured batch File

The example below shows a full featured batch file for the described dfu feature:

@ECHO OFF
echo BLACK MAGIC PROBE UPDATER
if "%~1"=="" (
	echo ERROR! Plz specify the BMP BIN file with the update!
	goto :EOF
)

if not exist %1 (
	echo ERROR! The specified file was not found!
	goto :EOF
)

echo Writing new firmware file: %1
dfu-util-static.exe -d 1d50:6018,:6017 -s 0x08002000:leave -D %1

Copy and paste this contents to a BMP-upgrade.bat file and save it to the same folder where the dfu-utility was extracted. I keep this batch file so I can easily perform upgrades in the future.

Now you can specify BMP-upgrade.bat <path-to-firmware> to perform any future upgrade.

Bonus Feature: STLinkV2 with VCP option

If you are not interested on the Black Magic Probe and still want to use the original STLink, with these change, you can convert your unit to STLink V2-1, supporting a Virtual COM Port.
Go and search for STLink-2_1_V2J37M26 (STM32+MSD+VCP).bin on the github. There are custom STLink projects which dumps a valid image. By writing it into the modified STLink board you will be able to use the debugger with VCP!

Personally, I find VCP much more useful than the SWIM interface.

APPENDIX A: Flash Size Issues With Firmware Version 1.10

When following this procedure with firmware 1.10 you will probably encounter a build error telling you that there is no more flash space:

  ...
  CC      platforms/common/aux_serial.c
  LD      blackmagic.elf
Memory region         Used Size  Region Size  %age Used
             rom:      140028 B       128 KB    106.83%
             ram:       11852 B        20 KB     57.87%
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: address 0x802216c of blackmagic.elf section `.text' is not within region `rom'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: blackmagic.elf section `.data' will not fit in region `rom'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: address 0x802216c of blackmagic.elf section `.text' is not within region `rom'
/usr/lib/gcc/arm-none-eabi/9.2.1/../../../arm-none-eabi/bin/ld: region `rom' overflowed by 8956 bytes
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:136: blackmagic.elf] Error 1
make: *** [Makefile:17: all] Error 2

The solution that I used was the suggestion in the issue ARM gcc 13.2.rel1 compatibility #1677. By removing the the efm32.c line of src/Makefile I've managed to compile the new firmware. Beware that this modification turned support for EFM32 off.