STM32 Debugging

From philcrump.co.uk
Jump to: navigation, search

Using a blackmagic probe.

Starting GDB

sudo arm-none-eabi-gdb \
    -ex "target extended-remote /dev/ttyACM3" \
    -ex "monitor swdp_scan" \
    -ex "attach 1" \
    -ex "file build/xxx.elf" \
    -ex "run"

To stop execution

Crtl+C

To print the stack backtrace

bt

To move up and down the stack

Frame numbers displayed at the start of the lines in the stack #n

f <n>

To print a variable value

p <varname>

To print in hex:

p/x <varname>

To call a function

call my_func()

Semihosting

Makefile

# user libraries
ULIBS += --specs=rdimon.specs -lrdimon
run: build/$(PROJECT).elf
	arm-none-eabi-gdb \
              -ex 'target extended-remote $(BMP_PORT)' \
	          -ex 'monitor swdp_scan' \
		      -ex 'attach 1' \
		      -ex 'load' build/$(PROJECT).elf \
		      -ex 'run'

Application

extern void initialise_monitor_handles(void);
 
int main(void) {
    initialise_monitor_handles();
    ...
    printf("Success!\r\n");
    ...