Generating Bin File for Dual Application Bootloader
Greetings,
I am creating a project with STM32CubeIDE for a STM32L4 microcontroller. My project consists of multiple components :
- Bootloader - Base program that jumps to one of my applications
- Applications - Application program for my project
- Python Script - Feeds the generated binary file of my application to the bootloader
My memory sections are as follow (copied from the bootloader project) :
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 64K
APP_SLOT_1 (rwx) : ORIGIN = 0x8010000, LENGTH = 192K
APP_SLOT_2 (rwx) : ORIGIN = 0x8040000, LENGTH = 256K
}
Whereas the section from my linker script of my application is :
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
FLASH (rx) : ORIGIN = 0x8010000, LENGTH = 192K or FLASH (rx) : ORIGIN = 0x8040000, LENGTH = 256K
}
Then I have to set the vector table offset in the application according to the flash location (system_stm32l4xx.c):
#define VECT_TAB_OFFSET 0x00010000U or #define VECT_TAB_OFFSET 0x00040000U
So, I have to determine these two settings followed by building the application project to generate the bin file. After that, I can manually write the flash memory pages with the bin file values and then my bootloader jumps to this program.
All this is working, allowing me to control which program my bootloader loads.
Here is my question :
I would like to generate .bin files that sets dynamically the vector table offset so I don't have to create a binary file for every application slot by changing the USER_VECT_TAB_OFFSET and memory sections. How can I do this?
So far I tried setting the Vector Table Offset Register SCB->VTOR in the bootloader before modifying the reset handler that jumps to my application.
I also tried setting SCB->VTOR in the application at SysInit. For this, I commented the definition of USER_VECT_TAB_ADDRESS.
I also set the memory section to include both application slots :
MEMORY
{
RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K
RAM2 (xrw) : ORIGIN = 0x10000000, LENGTH = 32K
FLASH (rx) : ORIGIN = 0x8010000, LENGTH = 448K
}
Even if my binary file is loaded properly at address 0x8040000 as seen from STM32CubeProgrammer, the bootloader always jump to the application at location 0x8010000 or back to the bootloader at 0x8000000.
I also tried generating a binary file from the .elf files using the Arm GNU Toolchain arm-none-eabi-objcopy. The generated binary file kept its static reference, so It would not work on the second application slot at 0x8040000.
