KL82: Can't jump to application from custom bootloader

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

KL82: Can't jump to application from custom bootloader

ソリューションへジャンプ
1,696件の閲覧回数
marcwillem
Contributor II

Hello,

I needed to implement a custom bootloader, as I am using a MCP2515 CAN Transceiver for flashing.

I can program the device without issue (verified by readback and MCUxpresso Memory Watcher).
When I jump to the application, I get a hardfault (unknown hard fault at 0x2900B289).

I can see the PC jumping to the application (0x0001 0000), but then it get's stuck somewhere.
The program is fairly simple but jumps to the hard fault handler immediately after the jump;

If I reset the program via SWD I get another hard fault, this time the PC is at 0F64, which is in my bootloader;

I configured the app in MCUxpresso for the flash to start at 0x00010000 (at C/C++ Build / MCU settings) and enabled position independent code.

This is the code of my application;

uint8_t i=0;
int main(void)
{
while (1) i++;
return 0 ;
}

 

This is how I jump to the application

#define START_OF_APPLICATION 0x00010000ul
static void (*go_to_app)(void) = 0;
go_to_app = (void (*)(void))(START_OF_APPLICATION);
SCB->VTOR = START_OF_APPLICATION;
__set_MSP(START_OF_APPLICATION);
__set_PSP(START_OF_APPLICATION);
go_to_app();

Did I forget anything?
Do you know why I get the hard fault or how I could debug it?

 

 

 

 

 

 

ラベル(2)
0 件の賞賛
返信
1 解決策
1,674件の閲覧回数
marcwillem
Contributor II

I found the solution here:
https://stackoverflow.com/questions/58296733/cortex-m0-jump-to-user-application-failing

#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();
}
  


 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,677件の閲覧回数
marcwillem
Contributor II

I figured I was missing the offset of 4 for calling the app.

static void (*go_to_app)(void) = 0;
go_to_app = (void (*)(void))(START_OF_APPLICATION+4);
SCB->VTOR = START_OF_APPLICATION;
__set_MSP(START_OF_APPLICATION);
__set_PSP(START_OF_APPLICATION);
__DSB();
go_to_app();

 

One issue is remaining, the application directly hard faults on execution. If I issue an reset from my debugging tool (SEGGER Ozone) it will start the application.

0 件の賞賛
返信
1,675件の閲覧回数
marcwillem
Contributor II

I found the solution here:
https://stackoverflow.com/questions/58296733/cortex-m0-jump-to-user-application-failing

#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();
}
  


 

0 件の賞賛
返信