I’ve been a long time an AVR user, but the technology is going ahead and it is time to use something more modern. Recently I started to look closer on the ARM microcontrollers and finally, I’ve selected STM32 Cortex-M3 as my base unit. For me, the perfect development environment would be QtCreator + GNU toolchain (since I use this environment on my work and I do not like Java-based IDEs). This post will be devoted to the hardware enabling on-chip debugging the STM32 applications using gdb.
In order to be able to use gdb, one need some adapter providing the interface between the debugger and ARM chip. I have considered several popular alternatives ST-Link from ST-Microelectronics, J-Link from Segger and Black Magic Probe from Black Sphere Technologies.
J-Link is a cool tool but it is really expensive. ST-Link is a nice and cheap tool and is supported by BareMetal plugin in QtCreator. In fact, gdb can’t work directly with ST-Link and you will need intermediate software like openocd to communicate with this dongle.
Black Magic Probe (BMP) implements gdb protocol natively and you do not need any additional software. BMP supports JTAG as well as SWD protocols, it has bootloader for updating firmware over USB. This dongle is also quite expensive for the hobbyist. Hopefully, the developer provides the schematics and firmware under the GNU Public License 3, and hence it is possible to create your own BMP use it for developing the commercial products and even sell the BMP clones. I’ve decided to build my own BMP with some minor modifications. First of all, I’ve selected the original version since it contains full-sized JTAG header. I’ve made the following modifications with respect to the original schematics: the mini-USB was replaced by USB-B one, the SWD header was added to simplify the flashing BMP chip.
Now it is time to build and flash the firmware:
git clone https://github.com/blacksphere/blackmagic.git
git submodule init
git submodule update
make -j4 PROBE_HOST=native
This will create a bootloader file and BMP firmware file. In order to make debugging dongle one need to have debugging dongle 🙂 Connect your favorite programmer to the SWD head on the BMP and flash it. Hier the ST-Link is used:
st-flash --flash=0x20000 write blackmagic_dfu.bin 0x8000000
st-flash --flash=0x20000 --reset write blackmagic.bin 0x8002000
The second command flashes the bootloader and the third one downloads the BMP firmware. Now it is time to connect BMP to your PC via USB an check if it is recognized. Use lsub command to see USB devices attached. If everything is fine you will see the following line:
ID 1d50:6018 OpenMoko, Inc.
then the device is recognized. To test gdb protocol just start gdb and issue the following commands:
(gdb) target extended-remote /dev/ttyACM0
(gdb) monitor version
Black Magic Probe (Firmware v1.6.1-269-g7cb1858) (Hardware Version 0)
Copyright (C) 2015 Black Sphere Technologies Ltd.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
In the next article, I will show how to configure BMP with QtCreator.