In STM32CubeMX, enable debugging: Pinout & Configuration > System Core > SYS > Mode > Debug: Enable
.
Then under Project Manager > Toolchain/IDE: Makefile
Inside VSCode, add a configuration in launch.json
:
{
"name": "GDB",
"type": "gdb",
"request": "launch",
"cwd": "${workspaceRoot}",
"target": "./build/oled_test.elf",
"gdbpath" : "/usr/bin/gdb-multiarch",
"autorun": [
"target remote localhost:3333",
"monitor reset init",
"monitor sleep 100",
"monitor halt",
"monitor sleep 100",
"load",
"break main",
"continue",
]
}
Flash your program:
st-flash write build/oled_test.bin 0x8000000
or use STM32 official flash programmer (you might need to have the exact paths to make it work on linux):
~/STMicroelectronics/STM32Cube/STM32CubeProgrammer/bin/STM32_Programmer.sh -c port=SWD -d build/oled_test.elf
Then run:
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg
Now set your breakpoints and hit F5
after choosing GDB
as debug configuration