Spark Logic

Black Magic Probe on an stm32f103c8

Rick Kimball

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

Replies20

Rick Kimball Wed Oct 26, 2016 2:24 pm

The one blue pill I have setup as a BMP programmer I had to replace the LDO with a microchip mcp1702. If I hadn’t shorted the power pins I’d still be using the original LDO. The mcp1702 is a 250mA max device and seems to work fine. Others have indicated the typical LDO on the blue pills are 300mA max. Seems like it would be fine with the one that ships onboard.

-rick

edogaldo Wed Oct 26, 2016 2:33 pm

Rick Kimball wrote:The one blue pill I have setup as a BMP programmer I had to replace the LDO with a microchip mcp1702. If I hadn’t shorted the power pins I’d still be using the original LDO. The mcp1702 is a 250mA max device and seems to work fine. Others have indicated the typical LDO on the blue pills are 300mA max. Seems like it would be fine with the one that ships onboard.

-rick

Rick Kimball Wed Oct 26, 2016 2:38 pm

Yes that is what I was doing. Of course if the target board is power hungry, that isn’t going to work.

michael_l Mon Dec 05, 2016 10:44 am

I’ve read almost the whole discussion but I can’t decide… I have two ST-Link V2 dongles and blue stm32F103c8t6 boards. Which option is suggested ?

1) Flash BMP FW into st-link using the second st-link dongle
2) Flash BMP FW into blue stm32F103c8t6 board

Rick Kimball Mon Dec 05, 2016 3:03 pm

michael_l wrote:I’ve read almost the whole discussion but I can’t decide… I have two ST-Link V2 dongles and blue stm32F103c8t6 boards. Which option is suggested ?

1) Flash BMP FW into st-link using the second st-link dongle
2) Flash BMP FW into blue stm32F103c8t6 board

michael_l Mon Dec 05, 2016 5:46 pm

Rick Kimball wrote:michael_l wrote:I’ve read almost the whole discussion but I can’t decide… I have two ST-Link V2 dongles and blue stm32F103c8t6 boards. Which option is suggested ?

1) Flash BMP FW into st-link using the second st-link dongle
2) Flash BMP FW into blue stm32F103c8t6 board

RogerClark Mon Dec 05, 2016 7:16 pm

BTW.

I tried to compile and flash the latest version of the BMP onto a STLink made by Baite ( the same company that sell the Maple mini clones)

But it doesn’t work at all. ( USB is not working)

I do have an old version of the BMP that works in those STLinks, which is based on Ricks BluePill port of the BMP.
But the BMP core code has changed a lot since Rick did has BluePill version, so its not possible to simply copy the platform files for the Baite STLink into the new code.

And at the moment I don’t have the time to bring the old code up to date, so I’m continuing to use the old version.

In the longer term however I was intending to do a Baite STLink “platform” and submit it as a PR.
However as Gareth is now doing a commercial push for to sell the BMP via kickstarter, I have a concern that doing this would allow Baite to bring out a $3 BMP, as they already use the same hardware has another programmer as well as a STLink, and it would be incredibly easy for them to drastically undercut Gareths price.

michael_l Mon Dec 05, 2016 7:30 pm

Thanks Roger, that’s good to know. Yes, ST Link dongle might be a bit more compact as a BMP compared to bluepill and it has that nice metallic cover too.Since I have another St Link V2 dongle it’s easy to flash any board.

I’ll try latest stlink binary and see how it works on bluepill.

RogerClark Mon Dec 05, 2016 7:41 pm

do you mean the BMP binary for STLink?

i would be surprised if it runs on the Blue Pill if it doesnt work on the Baite STLink as the Baite STLink is basically the same as the BluePill, just with much less GPIO.

Actually, after saying that… I guess i should look at the schematic for a STLink dongle vs a STLink on a Nucleo, as AFIK the BMP code is designed to run on a Nucleo or Discovery STLink and the USB enumeration reset circuit may be different between those 2 types of board.

Rick Kimball Mon Dec 05, 2016 7:51 pm

michael_l wrote:
EDIT: found these from platform.h
* TMS = PA4 (input for SWDP)

RogerClark Mon Dec 05, 2016 7:56 pm

Rick

Paypal link seems to be working again now. Perhaps it was an issue with paypal

can you try it again

Re: BMP not working on the Baite STLink dongle

ummm..

OK. I’m not sure what the difference is between the dongle and the Nucleo / Discovery hardware but perhaps it doesnt work on either at the moment

I don’t want to reflash any of my Nucleos as there is no way to get back to the version of stlink that uses USB mass storage and also has USB Serial ( as that binary has never been hacked and released)

But I think my Discovery F4 board doesnt have the mass storage, so I guess I could blow that away, but I’d loose USB serial so I could not go back to the original config by loading the hacked version of stlinks for the dongle

michael_l Mon Dec 05, 2016 8:12 pm

When I looked for a debugger I found “real” BMP just too expensive for a user beginning with STM32 boards. But the idea is great – to have GDB server ready on the board. Actually I started with Arduino’s but quickly found out that there’s not a decent debugger that does not cost fortune. I guess I’m the one of people who want sometimes do debugging step by step. ‘That’s why I started digging (in the other thread :-) ) how to use STM32Duino framework with ST Link with openocd. After some work and a patch in Arduino IDE debugging works. So with a little cost it’s possible to buy stm32 boards and develop in Arduino framework and debug also. I’m a programmer for over 10+ years and I understand the value of debugging but if the BMP price had been around $20 I may have bought it. Roger, do you have a paypal button somewhere so I can donate to you ?

RogerClark Mon Dec 05, 2016 8:31 pm

Michael

Re:Donations

Unfortunately if I accept donations, as it will almost certainly cause problems for me.

I provide the code etc, “as is”. I don’t make any guarantees that things work or that I will fix bugs.. As I simply don’t have time.

I’m sure that if I added a Donate button, that some people would make a donation and then expect some bug to be fixed in return.

I already get loads of unsolicited emails asking me for help with various projects. I used to respond politely saying that I can’t give individual help via email.
But I have received abusive emails when I’ve done that, so I simply do not reply to unsolicited emails any more.

Also. I’m sure the Australian Tax Office would tell me that “donations” were payment for services and hence taxable, and I’d need to individually account for each one, and declare them as part of the Business Activity Statement I have to do every 3 months

So the admin time involved would also make it not worth the hassle.

michael_l Mon Dec 05, 2016 8:47 pm

RogerClark wrote:Michael

Re:Donations

Unfortunately if I accept donations, as it will almost certainly cause problems for me.

I provide the code etc, “as is”. I don’t make any guarantees that things work or that I will fix bugs.. As I simply don’t have time.

I’m sure that if I added a Donate button, that some people would make a donation and then expect some bug to be fixed in return.

I already get loads of unsolicited emails asking me for help with various projects. I used to respond politely saying that I can’t give individual help via email.
But I have received abusive emails when I’ve done that, so I simply do not reply to unsolicited emails any more.

Also. I’m sure the Australian Tax Office would tell me that “donations” were payment for services and hence taxable, and I’d need to individually account for each one, and declare them as part of the Business Activity Statement I have to do every 3 months

So the admin time involved would also make it not worth the hassle.

Rick Kimball Mon Dec 05, 2016 9:09 pm

michael_l wrote:Rick, do you know if latest BMP source contains some important fixes ? Or should I be fine with this version ? Thanks

michael_l Mon Dec 05, 2016 9:17 pm

Thanks Rick for the help. Sorry if this is a basic question but does BMP need any drivers for Windows 7 ?

Image

Edit: found

http://www.blacksphere.co.nz/downloads/driver.w32.zip

Hmm.. these drivers don’t seem to work and install

Rick Kimball Mon Dec 05, 2016 9:58 pm

Changes I made to the latest standard BMP stlink platform to get it to run on a bluepill:

# I copied the src/platforms/stlink to src/platforms/bluepill
# then in the BMP/src directory:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: Makefile

Untracked files:
(use "git add <file>..." to include in what will be committed)

platforms/bluepill/

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/src/Makefile b/src/Makefile
index 8bc2659..55bc99e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -108,6 +108,6 @@ all_platforms:

include/version.h: FORCE
$(Q)echo " GIT include/version.h"
- $(Q)echo "#define FIRMWARE_VERSION \"`git describe --always --dirty`\"" > [email protected]
+ $(Q)echo "#define FIRMWARE_VERSION \"`git describe --always --dirty`-rk\"" > [email protected]

-include *.d
$ diff platforms/bluepill platforms/stlink
diff platforms/bluepill/Makefile.inc platforms/stlink/Makefile.inc
14c14
< LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8000000
---
> LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000
24c24
< .phony: install all host_clean
---
> all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex
26c26,32
< all: blackmagic.bin
---
> blackmagic_dfu: usbdfu.o dfucore.o dfu_f1.o
> @echo " LD [email protected]"
> $(Q)$(CC) $^ -o [email protected] $(LDFLAGS_BOOT)
>
> dfu_upgrade: dfu_upgrade.o dfucore.o dfu_f1.o
> @echo " LD [email protected]"
> $(Q)$(CC) $^ -o [email protected] $(LDFLAGS)
31,32d36
< install:
< openocd -f ~/openocd_cfg/st_nucleo_f103rb.cfg -c 'program blackmagic verify reset exit'
diff platforms/bluepill/platform.c platforms/stlink/platform.c
104c104
< //SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */
---
> SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */
diff platforms/bluepill/platform.h platforms/stlink/platform.h
66c66
< #define TMS_PORT GPIOA
---
> #define TMS_PORT GPIOB
70c70
< #define TMS_PIN GPIO4
---
> #define TMS_PIN GPIO14
$ make PROBE_HOST=bluepill clean all install

RogerClark Mon Dec 05, 2016 10:02 pm

Rick Kimball wrote:Changes I made to the standard BMP stlink platform to get it to run on a bluepill:

# I copied the src/platforms/stlink to src/platforms/bluepill
# in the BMP/src directory:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: Makefile

Untracked files:
(use "git add <file>..." to include in what will be committed)

platforms/bluepill/

no changes added to commit (use "git add" and/or "git commit -a")
$ git diff
diff --git a/src/Makefile b/src/Makefile
index 8bc2659..55bc99e 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -108,6 +108,6 @@ all_platforms:

include/version.h: FORCE
$(Q)echo " GIT include/version.h"
- $(Q)echo "#define FIRMWARE_VERSION \"`git describe --always --dirty`\"" > [email protected]
+ $(Q)echo "#define FIRMWARE_VERSION \"`git describe --always --dirty`-rk\"" > [email protected]

-include *.d
$ diff platforms/bluepill platforms/stlink
diff platforms/bluepill/Makefile.inc platforms/stlink/Makefile.inc
14c14
< LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8000000
---
> LDFLAGS = $(LDFLAGS_BOOT) -Wl,-Ttext=0x8002000
24c24
< .phony: install all host_clean
---
> all: blackmagic.bin blackmagic_dfu.bin blackmagic_dfu.hex dfu_upgrade.bin dfu_upgrade.hex
26c26,32
< all: blackmagic.bin
---
> blackmagic_dfu: usbdfu.o dfucore.o dfu_f1.o
> @echo " LD [email protected]"
> $(Q)$(CC) $^ -o [email protected] $(LDFLAGS_BOOT)
>
> dfu_upgrade: dfu_upgrade.o dfucore.o dfu_f1.o
> @echo " LD [email protected]"
> $(Q)$(CC) $^ -o [email protected] $(LDFLAGS)
31,32d36
< install:
< openocd -f ~/openocd_cfg/st_nucleo_f103rb.cfg -c 'program blackmagic verify reset exit'
diff platforms/bluepill/platform.c platforms/stlink/platform.c
104c104
< //SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */
---
> SCB_VTOR = 0x2000; /* Relocate interrupt vector table here */
diff platforms/bluepill/platform.h platforms/stlink/platform.h
66c66
< #define TMS_PORT GPIOA
---
> #define TMS_PORT GPIOB
70c70
< #define TMS_PIN GPIO4
---
> #define TMS_PIN GPIO14
$ make PROBE_HOST=bluepill clean all install

Rick Kimball Mon Dec 05, 2016 10:21 pm

It was just the latest version.
$ git pull
Already up-to-date.
$ git log
commit d6e29774feee9cad275f97d7e5c7fcfccfeb190b
Merge: dc9073b 085c980
Author: Gareth McMullin <[email protected]>
Date: Mon Dec 5 10:55:24 2016 +1300

Merge pull request #174 from ChuckM/sam4l

Target Driver for Atmetl AT91SAM4L target

Post a reply