Jump to app failing custom bootloader.

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

Jump to app failing custom bootloader.

跳至解决方案
3,403 次查看
mitch1
Contributor II

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.

标签 (1)
标记 (4)
1 解答
3,214 次查看
nxf56274
NXP Employee
NXP Employee

Hi,

Your settings have some problems.You can try the following code.

#define BL_APP_VECTOR_TABLE_ADDRESS 0x7d00
#define APP_VECTOR_TABLE ((uint32_t *)BL_APP_VECTOR_TABLE_ADDRESS)

void goToApp()

{

    static void (*farewellBootloader)(void) = 0;
   farewellBootloader = (void (*)(void))(APP_VECTOR_TABLE[1]);
   SCB->VTOR = (uint32_t)APP_VECTOR_TABLE;
   __set_MSP(APP_VECTOR_TABLE[0]);
   __set_PSP(APP_VECTOR_TABLE[0]);
   farewellBootloader();

}

在原帖中查看解决方案

3 回复数
2,898 次查看
OliveiraNxp
Contributor II

I received the same return from NXP on this case:

  • Project: AlarmSyatemG2
  • Case: 00333667
  • Date Opened:02/09/2021
  • Subject: LPC54616 - Jumping to a Custimized Legacy Boot Image

I Implemented the above code on my solution... Thanks!!!!

Oliveira
0 项奖励
3,215 次查看
nxf56274
NXP Employee
NXP Employee

Hi,

Your settings have some problems.You can try the following code.

#define BL_APP_VECTOR_TABLE_ADDRESS 0x7d00
#define APP_VECTOR_TABLE ((uint32_t *)BL_APP_VECTOR_TABLE_ADDRESS)

void goToApp()

{

    static void (*farewellBootloader)(void) = 0;
   farewellBootloader = (void (*)(void))(APP_VECTOR_TABLE[1]);
   SCB->VTOR = (uint32_t)APP_VECTOR_TABLE;
   __set_MSP(APP_VECTOR_TABLE[0]);
   __set_PSP(APP_VECTOR_TABLE[0]);
   farewellBootloader();

}

3,214 次查看
mitch1
Contributor II

That works perfectly, thank you!

0 项奖励