我有KL17,我正在尝试编写一个引导加载程序以允许OTA更新。我正在尝试跳转到用户应用程序时遇到问题。
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());
}
我这样称呼它:
JumpToUserApplication(PROGRAM_ADDRESS, (PROGRAM_ADDRESS+0x4));
我希望它会跳转到应用程序,但是实际发生的是引导加载程序实际上会重新启动,就好像它又回到了引导加载程序的重置...
WELCOME TO THE BOOTLOADER!
MSP BEFORE: 20005fc0
PSP BEFORE: 20006000
WELCOME TO THE BOOTLOADER!
MSP BEFORE: 20005fc0
PSP BEFORE: 20006000
... and so on.
感谢您的任何投入,谢谢!
答案 0 :(得分:0)
此方法有效:
#define PROGRAM_VECTOR_TABLE ((uint32_t *) PROGRAM_ADDRESS)
void jump_to_app(void)
{
static void (*go_to_app)(void) = 0;
go_to_app = (void (*)(void))(PROGRAM_VECTOR_TABLE[1]);
SCB->VTOR = (uint32_t)PROGRAM_VECTOR_TABLE;
__set_MSP(PROGRAM_VECTOR_TABLE[0]);
__set_PSP(PROGRAM_VECTOR_TABLE[0]);
go_to_app();
}
进行了一些更改,但是我注意到转到应用程序的引导程序地址解析为与我尝试的值不同的值。