Spark Logic

Black Magic Probe on an stm32f103c8

Rick Kimball Sat May 16, 2015 1:08 am

11/07/2017 – I attached a binary that can be loaded onto your blue pill in this post: viewtopic.php?f=37&t=2801

12/3/2016 – You can now contribute to developers of the Black Magic Probe project (which isn’t me) using paypal. Find and click the paypal contribute button here: https://github.com/blacksphere/blackmagic

12/8/2016 – Instead of using this port of Black Magic Probe, it is a lot easier to just compile the PROBE_HOST=stlink and load that onto your bluepill. The bluepill hardware is the same as the stlink v1/v2 hardware. Just follow the steps from the Black Magic Probe software for building and installing the BMP stlink platform. The advantage being, you will get the latest BMP version and you will be able to update future versions just using the USB cable on the bluepill with a program called usb-util. The posts in this thread can be thought of as an interesting read on my journey from bluepill newbie to a somewhat proficient users of it.

The Black Magic Probe is a modern, in-application programmer and debugging software for embedded microprocessors. It allows you to see what is going on ‘inside’ an application running on an embedded microprocessor while it executes. It is able to control and examine the state of the target microprocessor using a JTAG or SWD (Serial Wire debugging) port and on-chip debug logic provided by the microprocessor. The probe connects to a host computer using a standard USB interface. The user is able to control exactly what happens using the GNU source level debugging software, GDB. Read more about it here: https://github.com/blacksphere/blackmagic/wiki

However, the stm32duino crowd here will find the open source Black Magic firmware more appealing than the hardware. The Black Magic Probe firmware can be loaded onto the low cost stm32c8t6 boards you find on eBay. You can then use that clone board with BMP firmware to take the place of an ST-Link programmer. Once the BMP firmware is loaded on a clone board, it provides the ability to upload to the flash of another target board. It does this using a gdb server built into the BMP firmware. This allows for hardware debugging using just arm-none-eabi-gdb without any host server code.

I started with the latest github version of the Black Magic Probe software and added platform support for the stm32f103c8t6 boards you find on ebay. I call it the ‘jc66_coreboard’ platform, as that is the label printed on the silk screen. Any board with the same pin outs should work (See Red Pill Blue Pill post for more info about the hardware). The new platform is based mostly on the already existing stlink platform source with changes to support the different hardware pin outs and features.

The ebay “Red Pill” board loaded with the Black Magic Probe firmware acting like a programmer:
Image
by Rick Kimball, on Flickr

Target board (another “Red Pill” board) connections from the “Red Pill” BMP programmer:
Image

I’ve attached a zip file containing the blackmagic.bin file, the blackmagic elf file, and patch file for the source. ( NOTE: I will fork BMP github code and create a branch with the source changes). For now, just download and unpack the zip and then upload the bin or elf file to your jc66_coreboard.

If you want to build the source yourself, do something like the following:
$ git clone https://github.com/blacksphere/blackmagic
Cloning into 'blackmagic'...
remote: Counting objects: 3463, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3463 (delta 0), reused 0 (delta 0), pack-reused 3461
Receiving objects: 100% (3463/3463), 1.70 MiB | 0 bytes/s, done.
Resolving deltas: 100% (2331/2331), done.
Checking connectivity... done.
$ cd blackmagic
$ unzip ../bmp_jc66_coreboard.zip
Archive: ../bmp_jc66_coreboard.zip
inflating: blackmagic
inflating: blackmagic.bin
inflating: bmp_jc66_coreboard.patch
$ patch -p1 <bmp_jc66_coreboard.patch
patching file src/Makefile
patching file src/command.c
patching file src/platforms/common/cdcacm.c
patching file src/platforms/jc66_coreboard/Makefile.inc
patching file src/platforms/jc66_coreboard/Readme
patching file src/platforms/jc66_coreboard/jc66_coreboard.png
patching file src/platforms/jc66_coreboard/platform.c
patching file src/platforms/jc66_coreboard/platform.h
$ make
$ cd src
$ make install # assuming it go OK, you will have to change the path for the st-write utility to match your system

Replies

RogerClark Fri Jul 31, 2015 9:16 pm

Guys

I just soldered 2 small wires to my board, which i have now removed, as i can now upload via the bootloader.

I added a “generic-pa9” version to the bootloader to support this board ;-)
So the led on my board now flashes like it should.

Re:Readback

No. It was read locked.

There must be something in the STLink binary which sets the read disabled flag, as even if you download the stlink binary from those russian websites, and flash it into a F103, as soon as it starts running, you are no longer able to read the contents of flash back out.

I suspect it would be easy to hack the binary to prevent it doing this, i.e just look in the binary for the address of the locking register and change it for an address in ram.
That is… unless it checksums its self, but as its updates are uploaded in an encrypted form the devs may not have bothered to do that.

Overall, its not really worth messing around with the Stlink binary, as Black Magic Probe does as least as good a job and is open source.

I don’t really see much use for this board, unless someone had an application for something with very low pin count.
Perhaps a small data logger.

I dont know what pins it uses for its outputs on the connector at the end. I cant seem to find a schematic for the dongle version of the stlink, i can only find diagrams for the stlink on the discovery boards.

Anyway if the pins have analog capabilities, perhaps it could be used as a cheap data logger.

The other thing that this sort of device could be used for is for some basic form of encryption, e.g Rot13, just get the Serial USB to echo back Rot 13 versions of the incomming chars.

Or secure micro storage e.g keep your passwords in it. send the website address in via serial and it looks them up and sends back the username and password for that website.

Re: laser etching a different code.

Ive noticed that its very hard to read the markings on the devices on the stlink dongles.
I had to use a 10x eye glass, and hold it to bright sunlight, and look at an oblique angle to see it was an F101

Its like they made a half hearted attempt to remove the markings already.

Anyway, I guess the thing to do would be to test the RAM size as F101s have either 10 or 16k RAM not 20k, and to see if it has more than one USART, in which case its almost certainly a 103 in disguise ;-)

victor_pv Fri Jul 31, 2015 10:04 pm

RogerClark wrote:

I dont know what pins it uses for its outputs on the connector at the end. I cant seem to find a schematic for the dongle version of the stlink, i can only find diagrams for the stlink on the discovery boards.

RogerClark Fri Jul 31, 2015 10:32 pm

Victor

The only official schematics i can find are the ones for the discovery and nucleo boards, but the firmware on the Nucleo stlink is definitely not the same as on the Discovery as it also has USB serial.

I think the stlink software reads some version information and uses this to download the correct binary for the target board.

So i cant really guarantee that the schematics for the Discovery stlink section is the same as the dongle.
I did find this

http://www.micromouseonline.com/wp/wp-c … ink-v2.png

But it doesn’t seem to include the Reset line that the dongle has.

However i could test the Sdio and Sclk pins

victor_pv Fri Jul 31, 2015 11:05 pm

RogerClark wrote:Victor

The only official schematics i can find are the ones for the discovery and nucleo boards, but the firmware on the Nucleo stlink is definitely not the same as on the Discovery as it also has USB serial.

I think the stlink software reads some version information and uses this to download the correct binary for the target board.

So i cant really guarantee that the schematics for the Discovery stlink section is the same as the dongle.
I did find this

http://www.micromouseonline.com/wp/wp-c … ink-v2.png

But it doesn’t seem to include the Reset line that the dongle has.

However i could test the Sdio and Sclk pins

alex Sat Aug 01, 2015 1:43 am

How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.

RogerClark Sat Aug 01, 2015 2:12 am

alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.

victor_pv Sat Aug 01, 2015 2:20 am

RogerClark wrote:alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.

alex Sat Aug 01, 2015 10:17 am

@victor_pv You can’t load stlink fw to a stlink by usart directly since there’s no pads.
The only work order is:
1. Load stlink fw to blue/red pill by usart.
2. Load stlink fw to stlink by “blue/red pill stlink”.
So it’s a litte trouble. Maybe the best way is to buy another stlink.

Rick Kimball Sat Aug 01, 2015 4:28 pm

alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.

alex Sun Aug 02, 2015 1:44 am

Rick Kimball wrote:alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.

victor_pv Sun Aug 02, 2015 2:07 am

alex wrote:Rick Kimball wrote:alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.

ahull Sun Aug 09, 2015 11:51 am

I decided that years of Ram Pack Wobble experience suggested the best bet if I wanted to mess with the ST-Link V2 probes internal header was to solder the wires on rather than attempt to hold a tiny header in place.. This was relatively painless, but I did need a good magnifier, and almost set my hair on fire because my face was so close to the soldering iron while I was working.

Image

Not perfect, but not bad… It was only once I had finished the job that I realised I probably didn’t need to solder on the 3V3 and GND leads as I can access those signals on the jtag header.

More pictures here if anybody is interested.

Unfortunately since my other ST-Link V2 probe is at home, I can’t probe the probe at the moment.

zmemw16 Sun Aug 09, 2015 4:19 pm

link is 403 Forbidden – No Permissions

i stll keep trying to add images with file:///home/stephen…….

stephen

ahull Sun Aug 09, 2015 7:11 pm

zmemw16 wrote:link is 403 Forbidden – No Permissions

i stll keep trying to add images with file:///home/stephen…….

stephen

ahull Tue Aug 11, 2015 12:13 pm

For the record, (and this may have been mentioned before), you can upgrade a Generic ST-Link V2 clone with the utility on ST’s website here… – I have just verified that this works with Linux. Upgrade takes the probe to V2j24s4 released 22-Jul-2015 – see here for details.

Image

victor_pv Tue Aug 11, 2015 2:13 pm

ahull wrote:For the record, (and this may have been mentioned before), you can upgrade a Generic ST-Link V2 clone with the utility on ST’s website here… – I have just verified that this works with Linux. Upgrade takes the probe to V2j24s4 released 22-Jul-2015 – see here for details.

Image

RogerClark Tue Aug 11, 2015 9:20 pm

I managed to update all my STLink devices, as well…

Buy I have since installed the bootloader on my aluminium cased one.

madias Thu Aug 13, 2015 10:09 am

Can I trust my eyes? Is ST going to supportn more and more Linux and OSX? :shock:

Rick Kimball Tue Oct 20, 2015 4:42 am

alex wrote:How to load STLink binary to stlink with a BMP? In case I need it, gdb does not recognize the “STLinkV2.J16.S4.bin” file.
GDB has a “restore” command.
https://sourceware.org/gdb/onlinedocs/g … Files.html

(gdb) restore ../STLinkV2.J16.S4.bin
‘../STLinkV2.J16.S4.bin’ is not a recognized file format.
(gdb) restore ../STLinkV2.J16.S4.bin binary
Restoring binary file ../STLinkV2.J16.S4.bin into memory (0x0 to 0x10000)
warning: restore: memory write failed ((undocumented errno -1)).
(gdb) restore ../STLinkV2.J16.S4.bin binary 0x8000000
Restoring binary file ../STLinkV2.J16.S4.bin into memory (0x8000000 to 0x8010000)
Writing to flash memory forbidden in this context
(gdb)

zmemw16 Tue Oct 20, 2015 3:28 pm

nice trick

i finally got a sketch running under the debugger with serial output, not entirely sure how:-)
thanks rick.

what i have found is that for anything more than blink (just need to insert #include <Arduino.h> in the cpp file) it gets interesting, mainly with SPI and ‘standard’ definitions(PA4 etc).
i’m using the using-spi-ports example with my additions, heading towards a driving nokia 5110 (my success with adafruit_gfx_as is really, really non stella)
waggles are for my ols.

can anyone list the various headers needed for spi/i2c, the sequence and where they need to go, wrapper or cpp?
so i’m currently relying on the #ifndef’s for blocking a reload of the header files.
i’ve played with various commenting out of the headers. keeping all works, may well be overkill.

stephen

the wrapper is
#include <Arduino.h>
#include <SPI.h>
#include "using_SPI_ports.cpp"

Sign in to reply