0
votes

I'm trying to use OpenOCD with GDB to debug the STM32F4 Cortex-M4 on my STM32F4Discovery board.

Setup:

  • Ubuntu 16.04
  • OpenOCD 0.9.0 (also tested with 0.10-dev)
  • arm-none-eabi-gdb 7.10
  • STM32F4Discovery with ST-Link v2 (V2J28S0)
  • Project code generated with STM32CubeMX

I made sure debug wire is enabled in STM32CubeMX (this keeps the debug wire pins in default state)

GCC flags are:

-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0

I added simple blinking LED code to the main loop, to test the debugging.

I start OpenOCD with openocd -f board/stm32f4discovery.cfg -c "program build/discovery_simple_test.elf verify reset". OpenOCD flashes the chip and resets it. (Output of OpenOCD can be found here)

Now I connect to it with GDB:

(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x08001450 in ?? ()
(gdb) set verbose on
(gdb) file "/abs_path/build/discovery_simple_test.elf"
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Load new symbol table from "/abs_path/build/discovery_simple_test.elf"? (y or n) y
Reading symbols from /abs_path/build/discovery_simple_test.elf...done.
Reading in symbols for /abs_path/Src/main.c...done.
(gdb) monitor reset
(gdb) break main
Breakpoint 1 at 0x8000232: file /abs_path/Src/main.c, line 71.
(gdb) break /abs_path/Src/main.c:93
Breakpoint 2 at 0x8000258: file /abs_path/Src/main.c, line 93.

The program should break at line 93, but it doesn't.

When I halt the execution and try to continue it, it doesn't continue:

(gdb) monitor halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x080006d8 msp: 0x2001ffe8
(gdb) monitor continue
//Program doesn't continue

What is going on and how can I fix it?

3
Do you know for sure that you hit main function? Do you have the correct clock settings?staringlizard
Thank you for your comment. Clock settings were the default settings from STM32CubeMX. I have updated the on-board ST-Link to a J-Link adapter and I'm now using Segger's GDB server. Now I at least can continue with my project.i.amniels

3 Answers

0
votes

May be another GDB-Instance is Running ?
"A program is being debugged already." Look for a "arm-none-eabi-gdb" Process and kill it.

0
votes

I guess the command to use is just continue and not monitor continue since you have to tell GDB that the underlying software is running.

monitor continue tells the embedded system to continue but GDB does not know about it (it does not interpret the meaning of the monitor command, openocd does).

0
votes

To fix this issue i add the following command in openocd : -c gdb_breakpoint_override hard