void jump_to_app(void)
/* Clang at O0, stores variables on the stack with SP relative addressing.
* When manually set the SP then the place of reset vector is lost.
* Static variables are stored in 'data' or 'bss' section, change of SP has
* no effect on them.
static struct arm_vector_table *vt;
uint64_t flash_base = ABUP_FLASH_APP_ADDR;

vt = (struct arm_vector_table *)(flash_base);

vt->msp = *(uint32_t *)flash_base;
vt->reset = *(uint32_t *)(flash_base+4);

#if defined(__ARM_ARCH_8M_MAIN__) || defined(__ARM_ARCH_8M_BASE__)
/* Restore the Main Stack Pointer Limit register's reset value
* before passing execution to runtime firmware to make the
* bootloader transparent to it.

SCB->VTOR = ((int)(&(vt->msp)) & 0x1FFFFF80);


((void (*)()) vt->reset)();

Parents Reply Children
No Data