GD32 + libopencm3 + OpenOCD Debugging Notes



I am using GD32 for some projects. While it's claimed to be register-level compatible with STM32, and it's possible to use ST's tools and libraries, this is certainly an violation of ST's license. One possible solution is to use GD provided tools and libraries, but then it would be troublesome if some day I want to migrate back to STM32. So I ended up using libopencm3.

The following are just my personal notes. Environment: Arch Linux.

Install dependencies

Install the following packages from the official software repo:

# pacman -S arm-none-eabi-gcc arm-none-eabi-newlib

Install the following from AUR:

Create a new project

$ mkdir project
$ cd project
$ git init .
$ git submodule add
$ make -C libopencm3 -j5
$ wget -O
$ wget -O
$ cp libopencm3/lib/stm32/f1/stm32f103x8.ld .

Modify the last line of to:

include ../

Create a new src folder, copy an example from libopencm3-examples (.c and Makefile). Modify the Makefile as follows:

OPENCM3_DIR = ../libopencm3
LDSCRIPT = ../stm32f103x8.ld

include ../

Now make bin or make hex should generate the image.

Download using OpenOCD

Create a new configuration to use SWD:

$ cd /usr/share/openocd/scripts/interface
$ cp jlink.cfg jlink-swd.cfg
$ echo "transport select swd" > jlink-swd.cfg

Use OpenOCD to download:

openocd -f interface/jlink-swd.cfg -f target/stm32f1x.cfg
telnet localhost 4444
reset halt
flash write_image erase project.hex