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 Wed Jul 29, 2015 8:21 am

Thanks Alex

Its good to have that as reference.

alex Wed Jul 29, 2015 9:41 am

RogerClark wrote:Thanks Alex
Its good to have that as reference.

RogerClark Wed Jul 29, 2015 10:00 am

ok.

i will check

victor_pv Wed Jul 29, 2015 1:31 pm

alex wrote:

I have two blue pills already. They can be easily turnned into “st-link” just by connect B12 and B14 with a 100Ω resistor, flash st-link fw into it, B13 is SWCLK, B14 is SWDIO. I even made a adapter for it, I also modified the BMP source to use B13 and B14 for SWD, so I can use the same “diy adapter”.

But st-link clones are cheaper than the pills in my universe. Clone is about 13.5 CNY, and blue/red pill is about 20 CNY.

I use BMP mainly for semihosting to get rid of usb-ttl adapter, st-term is alse a choice for me.

alex Thu Jul 30, 2015 3:26 am

victor_pv wrote:
Yeah the price in the st-link clones is almost unbeatable, in part because they use STM32F100 rather and F103.
I am sure the BMP firmware can be adapted and flashed to it, but is it worth the trouble having to solder extra wires etc for the small price difference to get a red/blue pill?
I see them in taobao for just 17cny:
https://item.taobao.com/item.htm?spm=a2 … t=4#detail

And there are even better boards for just as cheap:
https://item.taobao.com/item.htm?spm=a2 … t=4#detail

Personally, unless you need a bunch of BMP, and converting the st-link can be done with no soldering at all, I dont think it’s worth the time, you time is probably more valuable used on something else.

RogerClark Thu Jul 30, 2015 3:54 am

@alex

I think it would be more fun to load the bootloader onto the stlink ;-)

The LED seems to be on PA9, and there appear to be 4 usable GPIO pins on routed to the connector at the end. I’m not sure if thats enough to do very much. You could connect a I2C periperal to 2 of those pins, or perhaps use them as analog inputs, e.g. some sort of mini data logger etc.

victor_pv Thu Jul 30, 2015 1:44 pm

alex wrote:
Using stlink as BMP is for tidy.
It very quik to convert the stlink to BMP, no soldering at all, just to make a 2.54 to 1.27 4 pins adapter first (in fact I already have one before for somethings else). Tools can save time.

alex Thu Jul 30, 2015 1:54 pm

to RogerClark: Do you mean load different firmware by usb for different usage? how to do that ?
to victor_pv: Usart is not available, you need to solder to A2 A3, but the good news is they are at corner.

RogerClark Thu Jul 30, 2015 10:03 pm

BTW

My STLink, which is in the same metal enclosure is a F103.

Re:Alternative software.

I mean use it as an Arduino. Flash the bootloader using another STLink board.
Not you can flash most F103 boards with the STlink binary to make them into an STLink board.
The binary for stlink is on various russian websites ;-)

victor_pv Thu Jul 30, 2015 11:45 pm

RogerClark wrote:BTW

My STLink, which is in the same metal enclosure is a F103.

RogerClark Fri Jul 31, 2015 12:03 am

Sorry,

I double checked. Both of my are F101’s :-(

Different boards, one is in the metal case, the other does to have a case

I wonder what the difference is between the F101 and the F103. I know the STLink binary works on the F103 boards, but I suppose that makes sense, as I presume the F103 is a better device than the F101

Edit.

I’ve just looked at the spec on the F101 and one key difference is the clock speed of 36 instead of 72Mhz. I’m not sure if there is anything in the bootloader which would prevent it working on the F101, and of course the core is generally set to 72Mhz, and I’m not sure whether if that value was changed in the core, whether it would work either, as we’ve never tried

Given that the F103’s are so cheap, I guess its hardly worth messing around with getting Arduino etc onto these F101 board (unless they were $1 or something).

victor_pv Fri Jul 31, 2015 5:29 am

RogerClark wrote:Sorry,

I double checked. Both of my are F101’s :-(

Different boards, one is in the metal case, the other does to have a case

I wonder what the difference is between the F101 and the F103. I know the STLink binary works on the F103 boards, but I suppose that makes sense, as I presume the F103 is a better device than the F101

Edit.

I’ve just looked at the spec on the F101 and one key difference is the clock speed of 36 instead of 72Mhz. I’m not sure if there is anything in the bootloader which would prevent it working on the F101, and of course the core is generally set to 72Mhz, and I’m not sure whether if that value was changed in the core, whether it would work either, as we’ve never tried

Given that the F103’s are so cheap, I guess its hardly worth messing around with getting Arduino etc onto these F101 board (unless they were $1 or something).

RogerClark Fri Jul 31, 2015 5:32 am

Victor

Umm.

Does that mean that these F101’s in the STLink adaptors are possibly F103’s ?

They are the same package, I really can’t see how its worth them making the 101 as well as the F103

victor_pv Fri Jul 31, 2015 5:36 am

RogerClark wrote:Victor

Umm.

Does that mean that these F101’s in the STLink adaptors are possibly F103’s ?

They are the same package, I really can’t see how its worth them making the 101 as well as the F103

RogerClark Fri Jul 31, 2015 5:49 am

Victor

Yes. I read the other day, the clock must be 48Mhz or 72Mhz for usb to work, as the USB clock speed is 48Mhz, and the F103 has 2 divider modes from the main clock, either divide by 1 or divide by 1.5

RogerClark Fri Jul 31, 2015 7:32 am

Well, I’ve managed to erase my new STLink but I can’t see to reprogram via STLink :-(

STLink will connect to the other STLink and reads this data

17:29:31 : Device ID:0x410
17:29:31 : Device flash Size : 128KBytes
17:29:31 : Device family :STM32F10xx Medium-density

However as soon as I try to program the device, STLink has an error and it disconnects.

I’m not sure if this is because both devices are connected to USB, and perhaps it would be better if I disconnect the target board from USB and just use the power and ground from the programmimg STLink, but this seems somewhat unlikely

However I’ll give it a go.

Edit.

OK. When I disconnected the STLink board from USB and powered it from the other STlink board, I was able to program it.

I installed the generic bootloader and the device appeared as a Maple DFU device, and I was able to upload the blinky sketch and which also prints to USB

So the STM32F101 microcontroller seems to work perfectly as a 128k STM32F103CB !

Victor you were soooo right ;-)

The new cheapest Arduino on STM32 looks like its the STLink dongle !
LED is on PA9

ahull Fri Jul 31, 2015 10:22 am

:D You beat me to it. I was in the process of modifying a 0.1″ header to use as a probe by bending the pins in to the correct spacing for the smaller header on my purple programmer yesterday, but real work inconveniently got in the way. I might continue with this when I’m back in the office next week.

Did you manage to read the existing flash before firing on the new program?

Have you thought of any projects that would benefit from the tiny USB dongle form factor?

I presume that this means that at 2.11 GBP (3.29 USD) this is the cheapest stm32duino on ebay… auction prices not withstanding.

With the Blue Pill costing not much more, having a RTC resonator and all the pins broken out for an extra 40 pence makes the StlinkV2 programmer less attractive, except where the project lends itself to the tiny case and low pin count.

However the “because you can” factor means I feel compelled to find some use for the programmer as stm32duino.

victor_pv Fri Jul 31, 2015 11:49 am

ahull wrote::D You beat me to it. I was in the process of modifying a 0.1″ header to use as a probe by bending the pins in to the correct spacing for the smaller header on my purple programmer yesterday, but real work inconveniently got in the way. I might continue with this when I’m back in the office next week.

Did you manage to read the existing flash before firing on the new program?

Have you thought of any projects that would benefit from the tiny USB dongle form factor?

I presume that this means that at 2.11 GBP (3.29 USD) this is the cheapest stm32duino on ebay… auction prices not withstanding.

With the Blue Pill costing not much more, having a RTC resonator and all the pins broken out for an extra 40 pence makes the StlinkV2 programmer less attractive, except where the project lends itself to the tiny case and low pin count.

However the “because you can” factor means I feel compelled to find some use for the programmer as stm32duino.

ahull Fri Jul 31, 2015 12:07 pm

I suspect that will depend on what price they are purchasing the 101 and 103 at, if there is little to choose between the two, then whichever makes the most profit is the one they will go for. More likely however is that some clever clogs will start laser etching 103cbt6 on the 101c8t6 chips and flogging them for the higher price.

victor_pv Fri Jul 31, 2015 4:28 pm

ahull wrote:I suspect that will depend on what price they are purchasing the 101 and 103 at, if there is little to choose between the two, then whichever makes the most profit is the one they will go for. More likely however is that some clever clogs will start laser etching 103cbt6 on the 101c8t6 chips and flogging them for the higher price.

Sign in to reply