I've got a KL17, I'm attempting to write a bootloader to allow for OTA updating. I'm having trouble jumping to user app, this is what I'm attempting.
void JumpToUserApplication(uint32_t userSP, uint32_t userStartup){printf("MSP BEFORE: %x \n", __get_MSP());printf("PSP BEFORE: %x \n", __get_PSP()); SCB->VTOR = userSP; // SET UP INTERUPT VECTOR TABLE FOR APP// set up stack pointer__set_MSP(userSP);__set_PSP(userStartup);void (*user_app)(void) = userStartup;user_app(); printf("BAD MSP AFTER: %x \n", __get_MSP());printf("BAD PSP AFTER: %x \n", __get_PSP());}
I call it as such:
JumpToUserApplication(PROGRAM_ADDRESS, (PROGRAM_ADDRESS+0x4));
I expect it to jump to the app, however what happens instead is the boot loader actually restarts as if it goes back to the bootloader reset...
WELCOME TO THE BOOTLOADER! MSP BEFORE: 20005fc0 PSP BEFORE: 20006000 WELCOME TO THE BOOTLOADER! MSP BEFORE: 20005fc0 PSP BEFORE: 20006000... and so on.
I've looked through the disassembly and there is stuff going on at the expected address.
I've got this set up in two projects, with the following memory maps.