Having trouble booting from Bank2 and jumping to Bank1 on STM32G474
Hello,
I'm working on an a project that uses an ST32G474, and it needs to run two different/independent applications. The project requires that from a reset, the device boots from Bank2 every time. The application in Bank2 will then decide if it is ok to then jump to, and start running the application that is stored in Bank1.
The dual-boot example from ST isn't exactly what is needed, because it flips the BFB2 option bit during each boot, to toggle between banks. My application requires to always boot from Bank2, and then jump to Bank1, without going through a reset operation.
From reset, I'm able to get App1 to run from Bank1 when BFB2 is cleared, and also from reset, I'm able to get App2 to start and run from Bank2 when BFB2 is set. However, when I try to jump from App2 to App1, I'm not succeeding. Through various different tests, it looks as though App2 somehow either jumps to itself, or I jump somewhere and just crash.
I've tried to figure this out reading various different posts about jumping to the system bootloader, etc., and the code below contains various things I've tried, some commented. I think when the BFB2 bit is set, the processor is remapping the memory, so that the start of Bank2 is at memory address zero. And I've tried jumping to 0x08000000, and to 0x08040000, but doesn't work in either case.
Just trying to figure out what I'm missing. Hardware guy here trying to get some firmware to work. Thanks for any insight.
void jump_to_App1(void)
{
void (*app_reset_handler)(void);
volatile uint32_t addr = 0x8000000UL;
//HAL_RCC_DeInit();
HAL_DeInit();
//SysTick->CTRL = 0;
//SysTick->LOAD = 0;
//SysTick->VAL = 0;
__disable_irq();
SCB->VTOR = addr;//FLASH_BASE;
app_reset_handler = (void*)(*(__IO uint32_t *)(addr + 4));
__set_MSP(*(uint32_t *)addr);
//HAL_DeInit();
app_reset_handler();
}
