Close

Connecting GDB to the BlackIce-II STM32L433

A project log for FPGA Experiments

Log book of FPGA adventures at home

tom-verbeureTom Verbeure 03/23/2018 at 06:382 Comments

In yesterday's log, I wrote about not being able to connect the STLink v2 to the STM32 of the BlackIce-II board. 

Right now, that still doesn't work, but I found a work-around: I installed the wonderful BlackMagic Probe firmware on the Blue Pill STM32F103 board, which converts the Blue Pill into a debugging dongle that's actually more powerful than the STLink v2!

An STLink v2 is essentially a protocol converter from USB to SWD. You still need OpenOCD as an intermediary to link GDB to your STM32.

Not so with the BlackMagic Probe: it has acts like a serial port on the USB side, has a GDB server built-in which drives a SWD or JTAG interface. OpenOCD is not needed anymore: you connect your GDB straight to the dongle.

How did I get there?

Install Black Magic Probe on the Blue Pill

This turned out to be a combination of this article: "Converting an STM32F103 board to a Black Magic Probe"and this article: "Programming an STM32F103XXX with a generic "ST Link V2" programmer from Linux" (which I already reference earlier.)

The first article assumes that you don't have an STLink v2 dongle and compiles then installs the BlackMagic firmware using a USB to Serial dongle instead. The second one tells you how to install anything with the STLink dongle.

I wanted to use the STLink dongle to install the BlackMagic firmware.

All in all, the procedure was pretty straightforward.

In the process of all this, I learned a little bit about this all works:

Connecting the Black Magic to the BlackIce-II

I wired the following signals:

Once you have BlackMagic Probe running on the Blue Pill, you can connect to it directly with gdb:

ubuntu@ubuntu-xenial:~/projects/BlackIce-II/firmware/iceboot$ arm-none-eabi-gdb  -ex "target extended-remote /dev/ttyACM0"
GNU gdb (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 8.0.50.20171128-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
.
Find the GDB manual and other documentation resources online at:
.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Remote debugging using /dev/ttyACM0
(gdb)

Note that this didn't work at first. Initially, I saw the following:

(gdb) monitor swdp_scan
Target voltage: unknown
SW-DP scan failed!

 It took me a long to time figure what was wrong. In the end, I solved it by wiring an additional GND wire between the Blue Pill board and the BlackIce-II board. So simple!

(gdb) monitor swdp_scan
Target voltage: unknown
Available Targets:
No. Att Driver
 1      STM32L4xx

Hurray!

(gdb) attach 1
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x080008e2 in ?? ()

 What happened now is that GDB has taken control of the ARM CPU. Whatever it was executing has been stopped now and that is that.

If you never replaced the firmware of the BlackIce-II STM32 controller, you interrupted the iceboat firmware, which allows one to download a new FPGA bitstream over the USB-to-Serial port.

Debugging Firmware on the BlackIce-II STM32

For now, let's just use an example of the existing firmware.

It looks like this on my console:

Remote debugging using /dev/ttyACM0
(gdb) atta 1
Attaching to Remote target
warning: No executable has been specified and target does not support
determining executable automatically.  Try using the "file" command.
0x080011d6 in ?? ()
(gdb) file ./output/iceboot.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from ./output/iceboot.elf...done.
(gdb) br main
Breakpoint 1 at 0x80012b4: file main.c, line 95.
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/ubuntu/projects/BlackIce-II/firmware/iceboot/output/iceboot.elf
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, main () at main.c:95
95      HAL_Init();
(gdb)

Success!

Discussions

nbenm wrote 04/29/2019 at 13:51 point

In the article you say "the BlackMagic Probe [...] has a GDB server built-in which drives a SWD or JTAG interface"

You also say "This ultimately controls SWD and JTAG pins on your Blue Pill"

But your example contains only "monitor swdp_scan"

What about jtag?

If I try "monitor jtag_scan" I have an error message:

JTAG device scan failed!

Can you please explain this, I don't understand.

I have search a long time and never found jtag example.

  Are you sure? yes | no

nbenm wrote 04/29/2019 at 13:30 point

SW-DP scan failed!

I found your solution by chance.
I just moved the GND cable to another pin, and everything started working (for monitor swdp_scan only). Thank you.

  Are you sure? yes | no