Close

STM32 Black Magic Probe flashing

A project log for Bluetooth Gamepad Phone Case

A bluetooth gamepad integrated into a phone case.

MaaveMaave 12/07/2017 at 18:281 Comment

I'll be using Black Magic Probe to program/debug my "core51822" nrf51822 modules. Cheap STM32 boards can be flashed with the BMP firmware. (Note: Maple Mini board didn't work, stick to STM32F103C8T6 boards). HaD gave a brief summary about BMPs:

https://hackaday.com/2016/12/02/black-magic-probe-the-best-arm-jtag-debugger/

Quick cost comparison of dev options:

-STM32F103C8T6 ($3) + FTDI serial adapter clone ($2) + core51822 or similar modules ($6) = $11

-NRF51 DK ($34)

-Segger J-Link EDU ($60 not incl shipping) + core51822 or similar modules ($6) = $66+

The STM32 parts were sourced from China. It'll be $15-$20 if shipped from the US. I already had the serial adapter from the Arduino work so this was cheapest route bay far. Also I swear the NRF51 DK was $100 when I first checked and that's why I went the STM32/core51822 route. Now it's only $34. This is a very tempting option since it's officially supported and easier to set up. The DK has SWD pins so it can flash other modules as well.

On to the Black Magic Probe flashing. All of the guides were for Linux so I used my VM, Thinking about it now I probably could have compiled using the Windows build of gcc. Oops, too late. If other people get into this I'll find/write a build script so that people can download the prebuilt firmware.

The two guides I mostly followed:

https://medium.com/@paramaggarwal/converting-an-stm32f103-board-to-a-black-magic-probe-c013cf2cc38c
https://gojimmypi.blogspot.com/2017/07/BluePill-STM32F103-to-BlackMagic-Probe.htm

in terminal:

mkdir mbp
cd mbp
wget https://raw.githubusercontent.com/jsnyder/stm32loader/master/stm32loader.py
chmod 774 stm32loader.py
sudo apt install python-pip
pip install pyserial --assume-yes
sudo apt install arm-none-eabi-gdb
 Wiring pic from the Medium guide. If you check STM32 board pinouts you'll see that A9 and A10 are TX and RX respectively.

Wire up the boards according to the guide, plug in the FTDI USB, pass through the FTDI in VirtualBox to the VM. It connects as /dev/ttyUSB0 as shown in dmesg:

dmesg | grep tty
sudo ./stm32loader.py -p /dev/ttyUSB0

Test build BMP firmware:

sudo apt-get install gcc-arm-none-eabi --assume-yes
sudo apt-get install dfu-util --assume-yes
git clone https://github.com/blacksphere/blackmagic.git
cd blackmagic
make

 
If that completes without errors then build the STM32 version

cd src
make clean && make PROBE_HOST=stlink

 
That creates blackmagic_dfu.bin and blackmagic.bin. Now the firmware is built and can be flashed to the STM32. Either hit reset on the STM32 or unplug/replug. Then flash:

sudo ./stm32loader.py -p /dev/ttyUSB0 -V -e -w -v ./blackmagic/src/blackmagic_dfu.bin

Unplug it all. We don't need the USB to serial anymore. Reset the STM32's boot1 jumper to 0. Plug it through USB. The BMP updater firmware doesn't work with Win10 so I have to install the libusbK drivers using Zadig as mentioned here:
https://docs.particle.io/faq/particle-tools/installing-dfu-util/core/#windows-32-bit

Have the STM32 plugged in, start Zadig, select Black Magic (Upgrade) in the dropdown, use the arrows to select libusbK, install driver. VirtualBox still didn't pass through, and I'm being dumb and lazy, so I just used the dfu-util Windows build and transferred blackmagic.bin to Windows. Use dfu-util v0.9. Some other guide I had been following used v0.6 but that caused issue for me.

http://dfu-util.sourceforge.net/releases/dfu-util-0.9-win64.zip

Check the device ID with:

dfu-util.exe -l

which returned "Found DFU: [1d50:6017]" etc, I guess that's it. Time to flash:

dfu-util.exe -d 1d50:6017 -s 0x08002000:leave -D blackmagic.bin

 Mine succeeded, the Black Magic device shows in Windows. If you get errors, check gojimmypi's account of fiddling with the memory.

I gave it a quick test in gdb as well. I was able to start gdb and set the target.
https://github.com/blacksphere/blackmagic/wiki/Useful-GDB-commands

Discussions

Bangybug wrote 08/28/2019 at 08:06 point

Maple mini board can actually be turned  to Blue pill. Easiest you can do is pulling USB D+ line (pin 23) to the 3.3v via 1.5 kOhm resistor.

Otherwise you will need to investigate the additional hardware on your Maple. Transistor keys and some resistors attached to usb lines, controlled by MCU pins,  https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/stm32duino-bootloader  If you modify bluepill bootloader and control the pull-up  on PA12(pin23).  

  Are you sure? yes | no