My notes on installing Black Magic Probe firmware on a cheap ($4) St-Link V2 clone.
Black Magic: GitHub
ST-Link V2 clone: Link to eBay
Compile from source
Did not work on GCC 6.1 from Fedora 25 repositories. The binary was too big.
arm-none-eabi-gcc (Fedora 6.1.0-2.fc25) 6.1.0
I had to download GCC 5.4.1 from Launchpad. With this version, compilation worked flawlessly. The compiler path can be specified in CROSS_COMPILE environmental variable. It has to be the path to the bin directory of the tool-chain installation followed by the prefix:
Complete compilation script
git clone --recursive https://github.com/blacksphere/blackmagic.gi cd blackmagic/ export CROSS_COMPILE="/home/tommz/apps/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-" make -j4 cd src make clean make -j4
This will result in two files:
- blackmagic_dfu.bin which is the bootloader, program from address 0x8000000
- blackmagic.bin which is the firmware, program from address 0x8002000
Flash the firmware
I used Segger J-Link to program the ST-LINK Clone.
[tommz@tommz-fedora]$ JLinkExe J-Link>connect STM32F101C8 Select SWD J-Link>loadfile blackmagic_dfu.bin , 0x8000000 J-Link>loadfile blackmagic.bin , 0x8002000
After programming and power cycling ST-LINK the Back Magic Probe shows up in dmesg:
[522051.728759] usb 3-14.6: new full-speed USB device number 112 using xhci_hcd [522051.818524] usb 3-14.6: New USB device found, idVendor=1d50, idProduct=6018 [522051.818525] usb 3-14.6: New USB device strings: Mfr=1, Product=2, SerialNumber=3 [522051.818526] usb 3-14.6: Product: Black Magic Probe (STLINK), (Firmware v1.6-rc0-267-ga0791f9) [522051.818526] usb 3-14.6: Manufacturer: Black Sphere Technologies [522051.818527] usb 3-14.6: SerialNumber: E4E785DB [522051.819884] cdc_acm 3-14.6:1.0: ttyACM0: USB ACM device [522051.820392] cdc_acm 3-14.6:1.2: ttyACM1: USB ACM device
ttyACM0 is the GDB extended remote console and the second is a USB to UART converter.
I tried to upload Blink example code into a cheap STM32F103C8T6 devboard from eBay. I downloaded a repository with examples from GitHub and changed the Blink example to use PC13 as the LED pin.
I connected the SWDIO, SWCLK and GND to the Black Magic Probe and plugged the dev board to usb (it is powered from USB).
The last step it to use GDB with the remote target to program and debug the MCU.
[tommz@tommz-fedora BlinkLed]$ arm-none-eabi-gdb GNU gdb (GDB) 7.6.2 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "--host=x86_64-unknown-linux-gnu --target=arm-none-eabi". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. (gdb) target extended-remote /dev/ttyACM0 Remote debugging using /dev/ttyACM0 (gdb) monitor swdp_scan Target voltage: unknown Available Targets: No. Att Driver 1 STM32F1 medium density (gdb) attach 1 Attaching to Remote target 0x08000260 in ?? () (gdb) load Blink.elf Loading section .isr_vector, size 0x10c lma 0x8000000 Loading section .text, size 0x26c lma 0x800010c Loading section .rodata, size 0x18 lma 0x8000378 Loading section .init_array, size 0x4 lma 0x8000390 Loading section .fini_array, size 0x4 lma 0x8000394 Loading section .data, size 0x4 lma 0x8000398 Start address 0x8000314, load size 924 Transfer rate: 7 KB/sec, 154 bytes/write. (gdb) run The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program:
First, I’ve connected to the remote target, then scanned the SWD bus, then attached to the first target, uploaded the binary and run the program.
So far, everything worked OK. Next step will be to enable debugging from IDE, specifically Eclipse which I use for writing my code.
I used the following sources:
- Compiling and flashing the ST-LINK V2 Clone: http://embdev.net/articles/STM_Discovery_as_Black_Magic_Probe#Using_cheap_STLink-clones
- Getting started with GDB for Black Magic Probe: https://github.com/blacksphere/blackmagic/wiki/Useful-GDB-commands