I am facing a problem, my application should allow to receive an update over the i2c interface.
I have devided the Flash memory into 2 equal parts, if the code is running from the lower part, it should save the new hex file to the upper flash part, and if the current application is running in the high part of the flash memory, it should save the new firmware in the lower part.
This is all working fine.
But now i don't know how to go further.
the complete hex file is lets say programmed in flash memory at the address 0x00020000
First of all i am rebasing the stackpointer back to the initial value so the complete stack is available again.
Second i am rebasing the vector table, but i don't know if that is correct.
Then i am fetching the entry point for the code to start running (can be found in the Vector table with an offset of +4 according to
This value should have an offset with the address i have put the code in (in my case being 0x00020000)
and then i try jumping to this address. below code shows how i am doing that.
This is not working. i am missing some knowledge i think.
Could someone explain me what the correct way is to tackle my problem?
/* Rebase the Stack Pointer */
__set_MSP(*(uint32_t *) application_address);
/* Rebase the vector table base address */
SCB->VTOR = ((uint32_t) application_address & SCB_VTOR_TBLOFF_Msk);
/* Load the Reset Handler address of the application */
application_code_entry = (void (*)(void))(unsigned *)(*(unsigned *)
(application_address + 4));
application_code_entry += application_address;
/* Jump to user Reset Handler in the application */