hellow,I encountered a rather tricky problem. I am using BootLoader+APP mode on S32K314. The same code works fine when the BootLoader jumps to the APP, but it triggers a hard fault when the app jumps back to the BootLoader. During debugging, I found that there was an error in setting up the stack. I can't think of a good solution for this issue and would like to ask if anyone has any suggestions?
The code and the values of the variables look like this:
addr =0x00400000
static void (*jump_to_bootloader)(void);
static uint32_t stack_pointer;
uint32_t appEntry, appStack;
appStack = *(uint32_t *)(addr + 4096);
appEntry = *(uint32_t *)(addr + 4096 + 4);
jump_to_bootloader = (void (*)(void))appEntry;
stack_pointer = appStack;
S32_SCB->VTOR = (uint32_t)addr;
__asm volatile("MSR msp, %0\n" : : "r"(stack_pointer) : "sp");
__asm volatile("MSR psp, %0\n" : : "r"(stack_pointer) : "sp");
jump_to_bootloader();