0

My application has an offset due to a bootloader and some configuration data that are located before the application address. When I debug the application without the bootloader I only have the offset of the configuration data which occupies one flash page (0x800) therefore the application is located at 0x08000800.

My linker script as well as my vector tab offset has been configured accordingly.

LD_DEVICE_SIZE = 512K;
LD_DEVICE_START = 0x08000000;
LD_BOOTLOADER_START = LD_DEVICE_START;
LD_BOOTLOADER_SIZE = 0x8000;
LD_MFG_DATA_START = LD_DEVICE_START;
LD_MFG_DATA_SIZE = 0x800;
LD_APP_START = LD_DEVICE_START + LD_MFG_DATA_SIZE;
LD_APP_SIZE = LD_DEVICE_SIZE - LD_MFG_DATA_SIZE;
LD_FLASH_START = LD_APP_START;
LD_FLASH_SIZE = LD_APP_SIZE;

/* Memories definition */
MEMORY
{
    RAM (xrw)       : ORIGIN = 0x20000000,          LENGTH = 160K
    RAM2 (xrw)      : ORIGIN = 0x10000000,          LENGTH = 32K 
    MFGDATA (rx)    : ORIGIN = LD_MFG_DATA_START,   LENGTH = LD_MFG_DATA_SIZE
    FLASH (rx)      : ORIGIN = LD_FLASH_START,      LENGTH = LD_FLASH_SIZE  
}

and

#ifdef DEBUG
    #define VECT_TAB_BASE_ADDRESS   FLASH_BASE
    #define VECT_TAB_OFFSET         LD_MFG_DATA_SIZE
#else
    #define VECT_TAB_BASE_ADDRESS   FLASH_BASE
    #define VECT_TAB_OFFSET         LD_BOOTLOADER_SIZE + LD_MFG_DATA_SIZE
#endif

I'm unable to debug my application with this offset. I can enter debug mode but when I resume, the debugger terminates.

I was looking at "Startup" in the Debug Configuration and tried to change the "Set program counter" as well as the "Set vector table". But this also does not work. I'm also not certain if these values should be from 0x00000000 or 0x08000000.

How would I go about debugging an application at an offset?

bluscape
  • 317
  • 3
  • 10
  • Can you explain the process and tools you use to enter debug mode? I feel like to even begin to answer your question, we also need to know which debugger you are using, and how. – Gabriel Staples Mar 30 '23 at 18:04
  • @GabrielStaples: it says stm32cubeide in the title and as a tag. In case you don't know, that's eclipse+gcc+gdb. – Tom V Mar 30 '23 at 20:14
  • @TomV, I see. I always used STM32CubeIDE for development, but [Ozone](https://www.segger.com/products/development-tools/ozone-j-link-debugger/) and the Segger J-Link device for code uploading and debugging (see [my answer](https://stackoverflow.com/a/57313990/4561887)). I suppose there are built-in debugging tools inside STM32CubeIDE now, and the OP is probably using an ST-Link? – Gabriel Staples Mar 30 '23 at 20:38
  • 1
    It would be simpler to always program the configuration data and application at the same addresses, for both debug and release builds. Note that you can run both debug and release builds without using the debugger, and you can run both debug and release builds with the debugger. I don't understand why you'd want to move everything around. – pmacfarlane Mar 30 '23 at 21:00

1 Answers1

0

Your definitions in the linker script are not consistent. You've set both LD_BOOTLOADER_START and LD_MFG_DATA_START to the same value.

I suggest you set:

LD_BOOTLOADER_START = LD_DEVICE_START;
LD_BOOTLOADER_SIZE = 0x8000;
LD_MFG_DATA_START = LD_DEVICE_START + LD_BOOTLOADER_SIZE;
LD_MFG_DATA_SIZE = 0x800;
LD_APP_START = LD_DEVICE_START + LD_BOOTLOADER_SIZE + LD_MFG_DATA_SIZE;
LD_APP_SIZE = LD_DEVICE_SIZE - (LD_BOOTLOADER_SIZE + LD_MFG_DATA_SIZE);

Then all you need to do is to set LD_BOOTLOADER_SIZE to zero or non-zero to select between debugging and non-debugging.

Plus also you need to always put parens around macro definitions that contain operators:

#define VECT_TAB_OFFSET (LD_BOOTLOADER_SIZE + LD_MFG_DATA_SIZE)

This might not be the whole problem with your debugging experience, but it will be a start in the right direction.

Tom V
  • 4,827
  • 2
  • 5
  • 22