2025-05-23 2:39 AM - edited 2025-05-23 4:32 AM
I have seen linker scripts like this:
MEMORY { RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K - 192 /* 192 for vector table */ BOOTLOADER (rx) : ORIGIN = 0x08000000, LENGTH = 4K FIRMWARE (rx) : ORIGIN = 0x08001000, LENGTH = 256K - 4K } /* Main app start address symbol */ _main_app_start_address = 0x08001000;
with multiple DRY issues.
After trawling through linker script documentation, I came up with the following alternative:
/* Entry Point */
ENTRY(Reset_Handler)
BL_ORIGIN = 0x08000000;
BL_SIZE = 32K;
FW_ORIGIN = (BL_ORIGIN + BL_SIZE);
...
/* Memories definition */
MEMORY
{
...
BOOTLOADER (rx) : ORIGIN = BL_ORIGIN, LENGTH = BL_SIZE
FIRMWARE (rx) : ORIGIN = FW_ORIGIN, LENGTH = 256K - BL_SIZE
}
...
where the symbol FW_ORIGIN can be used straight from c, e.g. using:
extern uint32_t FW_ORIGIN[];
const uint32_t FIRMWARE_START_ADDR = (uint32_t)FW_ORIGIN;
I did not see this suggestion anywhere when looking for ways to do this (using search terms like the title of this post), and it works, so I assume it is valid, or are there issues with this approach that I should be aware of?
2025-05-23 3:36 AM
Hello @EvO
There is no issue with your approach!
2025-05-23 4:15 AM
Have SystemInit use a Linker symbol to set SCB->VTOR automatically rather than use #define macros.
2025-05-23 4:33 AM - edited 2025-05-23 4:34 AM
Updated the labels: I am developing for STM32F0, so no VTOR....
But maybe there is a standard symbol for 0x08000000 that I could use to replace the define?