Debugging Cortex-M with ARM-GDB and ST-Link
Downloading and Installing ST-Link utilities
- Download ST-Link source from Github.
- Install the necessary requirements with
sudo apt install libusb-1.0.0-devon Debain systems. Use equivalent command on other distributions. cd st-link && makesudo cp build/Debug/st-* /usr/local/binorsudo cp build/Release/st-* /usr/local/binsudo cp /etc/udev/rules,d/49-stlinkv* /etc/udev/rules.d/sudo udevadm control --reload
Using ST-Link
Reading flash
st-flash --reset read content_flash.bin 0x8000000 0x20000
Debugging
- Run the st-link utility by
$ st-utilif it is already present in the path. This step sets up the debugging server. - Once the server is set up, run
$ arm-none-eabi-gdb file.elfand run the following command the GDB commandline> target extended-remote :4242(if the port selected by the previous step is 4242). Alternatively, this could also be done,arm-none-eabi-gdb --eval-command="target remote localhost:4242" file.elf - In the gdb command line, enter
> load file.elfand insert a breakpoint in main bybreak main.
Writing to flash
st-link write file.bin 0x8000000
Detecting the target
st-info --probe
Reference
Written on August 17, 2019