Setup
I am working on W10 and I am encountering a problem while following the tutorial from here. It is about writing baremetal code for ARM Cortex M3. The files produced by the above tutorial are startup.c
test_program.c
and stm32.ld
. All three files are in the same folder where I open a cmd window and I successfully compile and link them with the following successive commands:
arm-none-eabi-gcc -O0 -c -g -mcpu=cortex-m3 -mthumb -o test_program.o test_program.c
arm-none-eabi-gcc -O0 -c -g -mcpu=cortex-m3 -mthumb -o startup.o startup.c
arm-none-eabi-ld -Tstm32.ld -o test_program.elf startup.o test_program.o
arm-none-eabi-objcopy -O binary test_program.elf test_program.bin
The tools I am using are gcc-arm-none-eabi-9-2020-q2-update-win32.zip
from here and openocd
version 20200530
from here. For flashing I use the following procedure:
- In a new cmd window I run
openocd -f openocd.cfg
whereopenocd.cfg
contains the following:
telnet_port 4444gdb_port 3333source [find interface/stlink-v2.cfg]transport select hla_swdsource [find target/stm32f1x.cfg]# reset_config nonegdb_memory_map enable
- In another cmd window I run
telnet localhost 4444
thenreset halt
stm32f1x mass_erase 0
flash write_bank 0 test_program.bin 0
andreset halt
again - Finally in a fourth cmd window I run
arm-none-eabi-gdb
target remote localhost:3333
file test_program.elf
and here comes the problem ...
Problem
After I successfully start the debugger and I set the file to be debugged, I want to have a breakpoint at say line 7 of main() in test_program.c. I write in the gdb debugger window (the forth from above)
b test_program.c:7
press enter, the debugger saysBreakpoint 4 at 0x7c: file test_program.c, line 7.
- I then write
c
and press enter hoping that the execution will stop at the desired location. Instead the debugger says
Continuing.Warning:Cannot insert breakpoint 4.Cannot access memory at address 0x7cCommand aborted.
- However the
x
command works just fine at that memory. Writingx 0x7c0x7c
gives the result<main+4>: 0x4b042207
.
Question
Why is this happening? I remember that I used to have this working some time ago on an older laptop with W7 and some older versions of openocd and arm-none-eabi tools! What can I do to be able to have a proper debug again?
I know that writing delete
can allow you to step over each instruction, but I am interested in a proper functionality of the debugger! What am I doing wrong?