Jump to app failing custom bootloader.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Jump to app failing custom bootloader.

Jump to solution
4,234 Views
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.

Labels (1)
Tags (4)
1 Solution
4,045 Views
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();

}

View solution in original post

3 Replies
3,729 Views
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 Kudos
Reply
4,046 Views
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();

}

4,045 Views
mitch1
Contributor II

That works perfectly, thank you!

0 Kudos
Reply