Set up a STM32 bluepill as a blackmagic probe for beginner
#1
# Set up a STM32 bluepill as blackmagic probe

There exist a very nice solution to flash the PineTime called [Blackmagic](https://1bitsquared.com/products/black-magic-probe) probe.
Rather than connecting with OpenOCD or JLink to the probe you can just open the debugger gdb and connect to the PineTime.

The Blackmagic probe was an crowdfunding development and the source is available on Github and crucially there are also versions for other hardware than the blackmagic probe device. If you regularly work or develop with embedded devices it is probably worth to buy the original Blackmagic probe. If you are new and want to try things before spending more money there is an inexpensive option.

You can flash the blackmagic binary to a device generally called [STM32 bluepill](https://circuitdigest.com/microcontrolle...g-usb-port), a small ARM M3 micro controller board which is widely available for cheap.

This approach works, it however comes with it's own challenges:
1. A practical issue, the blackmagic.bin is larger than 64k but the flash memory of the bluepill is officially only 64k. The thing is unofficially the chip actually supports 128k but there seems to be a production selection process and you cannot be sure if your device supports 128k.
2. To flash the STM32 bluepill you need a st-link or serial flash device or something, but you want the blackmagic probe because you don't have that
3. The chip on the STM32 bluepill is called STM32F103C8T6. There are quite a lot of cheap(er) chinese clones of this chip out there often called CS32F103C8T6 and there can be problems with those.

So as a beginner, what to do ?
Searching on ebay I found one product in the UK that helped with the problems above.

[Link to STM32 bluepill on ebay](https://www.ebay.co.uk/itm/Genuine-STM32...Sw~bFWGQ18)

The seller claims to use the original chip, but crucially also one that supports 128k. Also and this is important, the seller has uploaded the Ardoino (Maple) bootloaded already. This means you can access the bluepill with the USB port right away and do not need another connection.

Obviously I don't know the seller and can't give any assurance that it always workes, but it did work in my case.

I would guess that you can find similar offers in other countries.

So, if you have a STM32 bluepill tha has already the [bootloader](https://github.com/rogerclarkmelbourne/A...Bootloader) installed then you can follow these steps to convert the STM32 bluepill into a blackmagic probe.

1. Install `dfu-util` if you don't have it already
2. Download [blackmagic binary](https://github.com/blacksphere/blackmagi...g-Firmware). For the bluepill the `st-link` variant is required. You can download the latest nightly from [here](http://builds.blacksphere.co.nz/blackmag...stlink.bin).
3. Connect the bluepill with an usb cable and check the dmesg for the connection message. Then check with `dfu-util -l` how it is listed.
4. In my case the device showed three lines, the only difference is the alt(ernative) flag from ( 0..2). For this guide you need alternative 2. The flag `-a 2` stands for alternative 2
5. Check the device ID. Mine was 1eaf:003 but I have seen other IDs in other guides. If you have a different ID you have to adjust the command in the next step
6. flash the blackmagic binary with this command:

```
sudo dfu-util -d 1eaf:003 -a 2 -D blackmagic-stlink.bin
```

__Note: in other guides you see a variant of this command with a flag `-s` and the address where to flash the binary. This is the function of the alternatives here and not required here__


It might be required to press the reset button on the board shortly before flashing

You should see a progress bar and then a happy result.

7. Reset the board.
8. The commands `lsusb` and `dfu-util -l` show the new device.
9. The gdb debugger is available as `/dev/ttyACM0`
10. See here for a [gdb getting started guide](https://github.com/blacksphere/blackmagi...ng-Started)

Sorry for the markdown format, The forum formatting seems not to be supported by Pandoc

More useful links:

https://circuitdigest.com/microcontrolle...rduino-ide

https://medium.com/@paramaggarwal/conver...13cf2cc38c

https://gojimmypi.blogspot.com/2017/07/B...Probe.html
#2
Hi here is an overview how to connect the PineTime and the STM32 Bluepill once it is converted to a Blackmagic probe:



[Image: TTthxkqwegUAPqePnQWXjLmC]



The connectors on the Bluepill are:
  • SWDIO : B14
  • SWCLK : A5
  • 3.3V : 3.3V
  • GND : GND
#3
Ha, and in the latest development, it is possible to use the SWD pins at the end of the bluepill as, well SWD pins rather than the pins B14 and A5 described before.

This allows you to connect the original PineTime SWD cable directly to the blackmagic-bluepill. No soldering on that side required.


Changes to the guide above:

(1)
Instead of the link above, download this firmware:
http://builds.blacksphere.co.nz/blackmag...swlink.bin

(there is only a small difference in the file name, ..sWlink.bin instead of ..sTlink.bin)


(2)
Consequently the command to flash the firmware has to change as well:

Code:
sudo dfu-util -d 1eaf:003 -a 2 -D blackmagic-swlink.bin
(remember, the address after -d might be different)


Rest is the same.

Pro-Tip  Big Grin : Turn around the bluepill, on the backside is another inscription with the layout for the 4 pins and can be read easily.


Btw, all available firmwares can be seen here:
http://builds.blacksphere.co.nz/blackmagic/

Way more detail is here, including a guide for bluepills that have no firmware flashed yet, including chinese copies.
https://buger.dread.cz/tag/black-magic-probe.html
#4
Hey, thanks for the post, looks super helpful.

I'm not too experienced with embedded work (looking forward to changing that), but it looks like the black magic probe has a lot of features and supports a lot of platforms. Given that the binary is 79k, which is only ~15k too large, do you think it may be viable to create a stripped down version just for the nRF52832? I'd be happy to give this a try myself when I have some time (and a dev board/kit), but if you have any insights/advice/warnings I'd love to hear it.

Seems like it would be a handy way to make development more accessible since it would take the guesswork out of whether or not someone is selling the 128k version or not (also, I'm sure many people like myself have the 64k lying around)
#5
Well, turns out I had some time to look into this sooner than I thought, and it ended up being pretty simple (but I haven't actually tested it yet). I still don't have an NRF52 device (my Pine Time or the dev board I ordered off AliExpress), but I was able to reduce the binary size and flash my 64k Blue Pill.

I made a fork on GitHub with my changes, and also uploaded a release: https://github.com/JShabtai/blackmagic/r.../nrf52only

I haven't tested it yet since I don't have a device to test with, but I can connect to it with GDB so I'm optimistic. If someone wants to test it, let me know if it works or not.

Also note that many of the blue pill devices have a 10k pull up on the USB line (R10), but this should be 1.5k. This may cause problems for you (https://amitesh-singh.github.io/stm32/20...-pill.html)

Edit: I got my Pine Time and was able to flash some firmware just fine. This build seems to work fine with the 64k blue pill boards Big Grin


Forum Jump:


Users browsing this thread: 2 Guest(s)