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 Tue May 19, 2015 11:39 am

Hi Rick,

No worries

I’m just doing the ancilliary script for Windows, hopefully the Linux stuff will be left untouched.

I’m looking at the windows bat file now, but I don’t know if I will get it finished tonight, as its 9:45 already and I have to make an early start tomorrow ;-(

Edit.

Seems a bit better when I use an external script

This is the final command string that is being called

C:\Users\rclark\Documents\Arduino\hardware\arduino_stm32\tools\win>C:\Users\rclark\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-gdb.exe -b 230400 -ex “set debug remote 0” -ex “set target-async off” -ex “set remotetimeout 60” -ex “set confirm off” -ex “set height 0” -ex “target extended-remote COM3” -ex “monitor swdp_scan” -ex “attach 1” -ex “x/wx 0x8000004” -ex “monitor erase_mass” -ex “echo 0x8000004 expect 0xffffffff after erase\n” -ex “x/wx 0x8000004” -ex “file C:\Users\rclark\AppData\Local\Temp\build8034241370519985939.tmp\sketch_may19a.cpp.elf” -ex “load” -ex “x/i *0x8000004” -ex “kill” -ex “tbreak main” -ex “run” -ex “detach” -ex “echo \n\n\n uploaded!\n” -ex “quit”

which strangely doesnt seem to give the same errors, even though the only fix up is the last slash in the elf file

I can’t fully test this, as I’ve not wired up my BMP to another board, I’m just running it on its own.

Anyway, I’ll commit the changes as they currently are, so you can check I’ve manually patched things correctly, and I’ll try to find time to wire up my BMP to another board tomorrow

RogerClark Tue May 19, 2015 11:44 am

Edit

I’ve pushed the changes

Rick, can you see if my manual patching is OK for you.

Cheers

Roger

Rick Kimball Tue May 19, 2015 12:25 pm

I just cranked up a windows xp VM session. On windows xp at least the file name is wrong. It looks like it needs to be quoted. The BMP part seems to work fine if you give it the proper name. I’m not sure how to quote quotes in the Arduino build system platform.txt for windows. Although, thinking about it. If the file name had spaces in linux it would probably fail too.

Do you know much about the argument quoting in platform.txt?

Here is what it looks like on windows xp:

win32xp.png
win32xp.png (69.58 KiB) Viewed 949 times

Rick Kimball Tue May 19, 2015 3:40 pm

RogerClark wrote:I’ve pushed the changes .. Rick, can you see if my manual patching is OK for you. …

RogerClark Tue May 19, 2015 9:17 pm

Rick

Thanks

I will give that a try

RogerClark Wed May 20, 2015 9:07 am

Rick,

Can you confirm the electrical connections.

In one of your previous postings, you said it needs between 10k and 100k pullup and 22 ohms inline. with TCK and TDIO

However I’ve looked at the BMP schematics https://raw.githubusercontent.com/wiki/ … c_mini.pdf and and https://raw.githubusercontent.com/wiki/ … ic-1.0.pdf

and I can’t see anywhere on either schematic that has those resistors

Is this a later addition than the pdf’s that are on GitHub.

Edit.

I tried your new upload pattern and it seems OK on Windows 7

However I have not connected my C8 BMP to another board as I’m not sure about the connections.

BTW. I had something strange go on with the USB Enumeration on Windows. I plugged in my F103ZET board that still has BMP flashed to it, but Windows initially reported unknown USB device (just on device), so I disconnected and connected my by F103C8 board with BMP on it, and I got the same result.

So I connected my STLink to reflash the C8 board and Windows then decided it could see the BMP USB devices

and now when I disconnect and reconnect either board all the BMP usb devices are enumerating OK

It looks like enumeration may be a bit flakey, but I guess thats a small price to pay for using an unmodified board as a BMP

BTW. Looking at the schematics it looks like BlackSphere are using PA8 for USB enumerayion, as its 1.5k to USB D+ so looks suspiciously as USB re-enumeration hardware

Rick Kimball Wed May 20, 2015 11:07 am

[Edit] Note: read my later post before believing any of what I’ve wrote here
http://www.stm32duino.com/viewtopic.php … t=30#p1169

You do not need any resistors, inline or pull-down or pull-up. I’ve left this post here to
let you see how I had previously decided to suggest the use of them.

[/Edit] RogerClark wrote:
In one of your previous postings, you said it needs between 10k and 100k pullup and 22 ohms inline. with TCK and TDIO

Rick Kimball Wed May 20, 2015 11:25 am

RogerClark wrote:
So I connected my STLink to reflash the C8 board and Windows then decided it could see the BMP USB devices
and now when I disconnect and reconnect either board all the BMP usb devices are enumerating OK
It looks like enumeration may be a bit flakey, but I guess thats a small price to pay for using an unmodified board as a BMP

Rick Kimball Wed May 20, 2015 1:46 pm

Ok, further investigation leads to more information.

I had looked at the BMP Native schematic and compared it to the STLink one and wondered why the BMP didn’t have any resistors.

I have been testing with with my jc66_coreboard on a breadboard. I hadn’t removed it from the breadboard before I started testing all this stuff. After a conversation in ##stm32 about the proper resistors for the SWD lines. They suggested that no resistors are needed. I pulled my jc66_coreboard with the BMP firmware off the breadboad and just connected the wires directly to my target board and it worked just fine.

So you probably don’t want your BMP board on a breadboard when you are trying all this out. If you do the capacitance on the breadboard might be causing issues. By the same token, if your target board is on a breadboard it might also cause problems.

The bottom line don’t use any resistors between the BMP and the target.

Thanks go to the ##stm crew!

[Edit] And here is why we don’t need pull downs and pull ups ( they are internal )
http://www.st.com/web/en/resource/techn … df#page=19
[/Edit]

-rick

Rick Kimball Wed May 20, 2015 7:24 pm

I updated the zip file on the first post. I created a github fork project of the blackmagic code and made the source changes in the jc66_coreboard branch. See the first post of this thread for the url.

-rick

RogerClark Thu May 21, 2015 8:25 am

Rick

With the pull up or pull down

As the value of the pull-up is between 10 and 100k, is there any reason that the BMP code doesn’t use the internal pull up or pull down as required.

According to the page you liked to, TCK is always pulled pow, and TDIO always is pulled up.

I’m not sure why TCK needs to be pulled down, I didn’t realise it was bidirectional pin.
But I can see why TDIO needs to be either open collector or input pull up etc.

Rick Kimball Thu May 21, 2015 9:59 am

RogerClark wrote:I’m not sure why TCK needs to be pulled down, I didn’t realise it was bidirectional pin.
But I can see why TDIO needs to be either open collector or input pull up etc.

RogerClark Thu May 21, 2015 11:42 am

Hi Rick,

No worries

When I get chance I’ll try hooking it all together, but I’ve had some other non-Arduino stuff I’ve needed to do over the last few days

Cheers

Roger

Rick Kimball Thu May 21, 2015 1:49 pm

RogerClark wrote:According to the page you linked to, TCK is always pulled pow, and TDIO always is pulled up.

I’m not sure why TCK needs to be pulled down, I didn’t realise it was bidirectional pin.
But I can see why TDIO needs to be either open collector or input pull up etc.

Rick Kimball Thu May 21, 2015 7:44 pm

So more insight. Today I was loaded the code onto one of the blue generic stm32f103c8t6 boards. It didn’t enumerate after reset. In fact it didn’t enumerate after I unplugged it and plugged it back in. When I measured the resistance between (PA12) USBDP+ and 3.3v it is 10k .. instead of 1.5k ..

Does anyone have a schematic for these boards I didn’t see a transistor that might be used to control it. Hmm .. bummer.

-rick

RogerClark Thu May 21, 2015 8:30 pm

My larger C8 board doesn’t enumerate either.

It’s probably got either no resistor or a high value.

Would it be possible to turn on the internal pull-up. I know its a high value ( I can’t recall what value), but the internal and external values in parallel may be enough to re enumerate.

Also how about putting the USB pin, (pa12) into push pull and driving it high

Rick Kimball Thu May 21, 2015 9:34 pm

This is a false alarm. Now it is working for me.

I cleaned the board to make sure flux wasn’t any issue and now it works. But it still measures 10k .. so I have no idea what is going on there. On the red board I can identify the 1.5k resistor. On this board there is no 1.5k resistor in sight.

BTW: I’m talking about this specific blue pill board http://www.ebay.com/itm/321569700934

-rick

RogerClark Thu May 21, 2015 9:57 pm

Rick

OK.

Shame the Blue boards are different from the red ones. Well, it actually sounds like there are red boards that exhibit the same traits as the blue boards or a mix of traits.

I would suggest that we post a picture of the boards that work, but… I know a lot of eBay vendors just use stock images, so there is no way to know for sure you will get whats in the picture, unless you pre-confirm with the vendor first.

Rick Kimball Thu May 21, 2015 10:11 pm

Yeah I’ll take a picture of it. My board is actually different from the picture of the one the vendor displayed.
Dark here now. I’ll do it tomorrow.

-rick

Sign in to reply