Working and debugging with an STM32 can be summarized as follows:
We will skip the first part and jump directly to the debugging part
Install gdb:
gdb-multiarch
Find out your openocd commandline for a gdb server creating.
When you do "make flash" the console output will be similar to this:
$ make flash
FLASH usart_spsgrf-868.hex
(echo "halt; program /tardisnew/data/home_memeruiz_data/local/src/repos/gitlab/arcoslab/libopencm3-plus-examples/examples/stm32/l1/steval-ids001v4m/usart_spsgrf-868-spirit1/usart_spsgrf-868.hex verify reset" | nc -4 localhost 4444 2>/dev/null) || \
openocd -f interface/stlink-v2-1.cfg \
-f target/stm32l1.cfg \
-c "program usart_spsgrf-868.hex verify reset exit" \
2>/dev/null
From here you can extract your openocd commandline
Run this in a separate console:
openocd -f interface/stlink-v2-1.cfg -f target/stm32l1.cfg
Go to the your miniblink example directory and run:
gdb-multiarch <example_program>.elf
Run the following commands in gdb:
target remote localhost:3333
monitor reset halt
load
This will connect to the server and load your program in it
"r" (or "c"): Continue execution
"b <linenumber | file:function,file:line": Create breakpoint
"disable": Disable breakpoint
"enable"
"n": execute next line of code, (don't dive in functions)
"step": next instruction, dive in functions
"l": list context code
"p": print a variable data
"clear": clear all breakpoints
"info b": Display breakpoint info
"jump +1": skips current line and jumps to next line. Combine it with:
"tbreak +1": sets a temporary breakpoint at the next line
"stepi/nexti": step through an individual instruction
"delete": get rid of all the breakpoints
"bt": print backtrace of all stack frames
"info locals": see local variables
"x/2xw 0x2009C018": show 2 words(in hex!) starting from memory address 0x2009C018
"set {uint32_t}0x2009C018 = 0x400000": set value of memory address 0x2009C018 to 0x400000
Print register content [1]:
info registers
info all-registers (for neon Q on ARM)
i r <register name>
i r a (all registers)
i r f (floating point regs)
p $s0.f
p $s0.u
Set a register:
set $eax=0
When in asm or split layout, will display the register, assembler, and command windows.
layout split
[1] https://stackoverflow.com/questions/5429137/how-to-print-register-values-in-gdb
[2] https://www.geeksforgeeks.org/gdb-step-by-step-introduction/
[3] https://rhye.org/post/stm32-with-opencm3-5-fault-handlers/