STM32L475RG - Having trouble jumping between multiple .bin programs in flash, program stops working.
CURRENT PRODUCT
Our existing devices have a custom USB DFU bootloader starting at address 0x08000000. Our main application starts at 0x08008000, after 32Kb of space. I can jump from the main app to the bootloader with no issues (using a NVIC_Systemreset) and back from the bootloader to the main application.
NEW FEATURE
I need to extend the capability of the bootloader to include OTA, however, existing customers are not able to re-program the bootloader without special tools. So the bootloader code (0x08000000) portion MUST stay the same.
ATTEMPT
My solution is to add the OTA portion at 0x08008000 (PROGRAM 1) and shift the main application up to 0x08010000 (PROGRAM 2). I made adjustments to each linker script and in the system_stm32l4xx.c to ensure the VTOR is 0x08008000 for PROGRAM 1 and 0x08010000 for PROGRAM 2. When I look at the memory map the SP seems correct with each address 0x08008000 and 0x08010000 having a value of 0x20010000.
When I jump I use the following code block from DFU example:
void Jump2App(void)
{
/* Test if user code is programmed starting from address USBD_DFU_APP_DEFAULT_ADD */
JumpAddress = *(__IO uint32_t*) (USBD_DFU_APP_DEFAULT_ADD);
/* At location should be 0x20010000 which when & with 0x2FFE0000 = 0x2000000*/
if(((*(__IO uint32_t*)USBD_DFU_APP_DEFAULT_ADD) & 0x2FFE0000 ) == 0x20000000)
{
/* Jump to user application */
JumpAddress = *(__IO uint32_t*) (USBD_DFU_APP_DEFAULT_ADD + 4);
JumpToApplication = (pFunction) JumpAddress;
/* Initialize user application's Stack Pointer */
__set_MSP(*(__IO uint32_t*) USBD_DFU_APP_DEFAULT_ADD);
JumpToApplication();
}
}In which I have the USDB_DFU_APP_DEFAULT_ADD to 0x08010000 in PROGRAM 1, so PROGRAM 1 should be able to jump to PROGRAM 2.
PROBLEM
I program the device by creating a .DFU file of both PROGRAM binaries at the correct address. I put the device in bootloader mode and then I program the DFU file. The program correctly jumps to my new OTA bootloader code at 0x08008000. The program then correctly jumps to PROGRAM 2 at 0x08010000. However, on power up/down, this no longer works! The device fails to boot-up, and I'm measuring 3.3V at the appropriate pins.
I Am not even sure if my approach is the best solution, regardless, it does not seem to work.
Any help would be appreciated.