Hello everyone,
I designed a bootloader which retrieves an hex file online and writes the content in the flash memory. This works great, no problem there.
Once this is done, I use the following code to jump to the downloaded code:
void new_boot(void) { uint32_t app_check_address; uint32_t *app_check_address_ptr; if (!( WDT ->CTRL.reg & WDT_CTRL_ALWAYSON)) WDT ->CTRL.reg &= ~WDT_CTRL_ENABLE; app_check_address = APP_START_ADDRESS; app_check_address_ptr = (uint32_t *)app_check_address; if (*app_check_address_ptr == 0xFFFFFFFF) return; SystemInit(); __disable_irq(); /* Pointer to the Application Section */ void (*application_code_entry)(void); /* Rebase the Stack Pointer */ __set_MSP(*( uint32_t *) APP_START_ADDRESS); /* Rebase the vector table base address TODO: use RAM */ SCB->VTOR = (( uint32_t)APP_START_ADDRESS & SCB_VTOR_TBLOFF_Msk); /* Load the Reset Handler address of the application */ application_code_entry = (void (*)(void))( unsigned *)(*(unsigned *) (APP_START_ADDRESS + 4)); /* Jump to user Reset Handler in the application */ application_code_entry(); }
But it stalls.
If I run new_boot() right at the start of my main() function, it works perfectly and the previously downloaded code runs.
Specifically, new_boot() only fails if I run it after a SERCOM initialization (usart, spi...).
I suspect I have to disable something before moving but I just cannot figure what.
Any clue ?
Thanks,
Fred