STM32 Microcontroller with GDB: debugging doesn't work when I change flash structure

0

I want to debug my application for the STM32F107 microcontroller using JLinkGDBServer and the arm-none-eabi-gdb client. I am using the startup assembly file and the linker script provided by default by ST for the STM32F107 microcontroller.

Everything works fine if I don't modify the linker script: on one terminal window, I run arm-none-eabi-gdb, and in another terminal I run the GDB server as JLinkGDBServer -select USB -device STM32F107RC -if SWD -speed auto. Then on the GDB client I connect to the server on port 2331, load my elf file, monitor semihosting enable, monitor reset, and finally continue. The program starts at the Reset_Handler (I see its address writen into the PC Register) and runs perfecty, and I even see my std out on a new terminal window running telnet on port 2333.

The problem runs when I modify the LD linker script in order to have custom addresses. The default FLASH part starts at 0x08000000, but I want to reserve that space for a bootloader and some other data, and store my program at 0x08004000. After this change in the linker script, I follow the same steps as before for debugging, but it doesn't work. My application seems to start at some random address, not at the Reset_Handler. However, according to the output of the GDB server, the address of Reset_Handler is correctly written into the PC register.

What am I missing?

Dani S.

Posted 2019-02-08T16:36:48.527

Reputation: 1

Answers

0

The problem was the location of the ISR vectors. I needed to write the ISR vectors offset to the VTOR register. Also, performing a monitor reset from GDB won't perform an actual reset, because it will load the SP register with the value found in the beginning of the flash memory, which is not where my vectors are anymore. However the PC register does seem to be loaded correctly. To summarize, in my startup code I added 2 things: 1) I set the VTOR register. 2) I initialized the SP register to the beginning of the stack. After that, it works fine.

Dani S.

Posted 2019-02-08T16:36:48.527

Reputation: 1