For failsafe update of firmware we have implemented a simple secondary bootloader which will load our application after checking CRC32. The problem is when the seondary bootloader code calls through function pointer the address of ResetISR function of application from Vector table, the RestISR function of Secondary bootloader gets executed. Here is the code from secondary bootloader that calls the application code:
void (*runApplication)(void) = 0;
uint32_t runApplicationAddress = *((uint32_t *)0x00000804UL);
runApplication = (void (*)(void))runApplicationAddress;
SCB->VTOR = (uint32_t)0x00000800;
runApplication(); /* This line calls the ResetISR of secondary bootloader although the address in the register for BLX instruction is correct for application's ResetISR.*/
Seondary bootloader is using flash area from 0x0000 - 0x0800; Application is using 0x800 - 0x10000
The code is running on Kinetis MKL13Z64, IDE MCUXpresso 11.1.0
While debugging I can see the ARM instruction for runApplicaiton() is "blx r3" and in r3 register the address is correct but it does not jump to that address, which is of application's ResetISR but to it's own.
Thanks in advance!