S32K314 app jump to bootloader question

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

S32K314 app jump to bootloader question

跳至解决方案
1,875 次查看
Faith-Herio
Contributor II

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();
 
0 项奖励
回复
1 解答
1,848 次查看
Faith-Herio
Contributor II
0 项奖励
回复
4 回复数
1,718 次查看
shuaige
Contributor I

hello ,can you teach me how to address this question?Thank you?Why not jump?

0 项奖励
回复
999 次查看
Faith-Herio
Contributor II

Note to check if the RTOS is used. If RTOS is used, pay attention to the usage of the MSP and PSP registers before jumping. If the boot loader does not apply RTOS, you need to change your stack usage to the MSP register. Similarly, if the RTOS is used in the APP or BOOT, you need to change your main stack to the PSP before jumping.

0 项奖励
回复
1,849 次查看
Faith-Herio
Contributor II

已解决

0 项奖励
回复
997 次查看
Faith-Herio
Contributor II

Note to check if the RTOS is used. If RTOS is used, pay attention to the usage of the MSP and PSP registers before jumping. If the boot loader does not apply RTOS, you need to change your stack usage to the MSP register. Similarly, if the RTOS is used in the APP or BOOT, you need to change your main stack to the PSP before jumping.

标记 (1)
0 项奖励
回复