Hi,
How the bootloader to jump into application? When program jumps into the application, the mcu will reset. I use the function below to jump, does it work?
void JumpToExecute(uint32_t SP, uint32_t Startup)
{
volatile uint32_t avoid_optimization;
/* In order to avoid optimization issue when -Os */
avoid_optimization = SP;
/* In order to avoid optimization issue when -Os */
avoid_optimization = Startup;
/* set up stack pointer */
__asm("msr msp, r0");
__asm("msr psp, r0");
/* Jump to PC (r1) */
__asm("mov pc, r1");
}
Thanks & regards,
Jim
Hi Kim,
Could you possibly try this:
typedef void (*func_ptr)(); // pointer to function type
void JumpToExecute(unsigned int SP, unsigned int Startup)
{
__asm("mov r13, r0"); // Store it to SP (R13)
(*(func_ptr)Startup)(); // Jump at Startup
}
Hope it helps.
S.
Hi Stanislav,
I am using MKM34Z processor and Jump to Application code just like you mentioned, but program cannot exit Reset_Handler. I am using IAR and Reset Handler is below;
What do you think is the reason, where am I doing wrong? I would be glad if you help. Thank you.
Hi Mehmet,
If I understand your issue correctly you are able to jump to the application code (Reset_Handler) but it either never leaves it.
I'd suggest you to deinitialize all the interrupt sources (peripherals) used by the bootloader before you jump to the application code.
see e.g. https://community.nxp.com/message/1339695#comment-1341598
Hope it helps.
Stan
Hi,
__asm("ldr r0,=main"); //load address of main function (use any address you need)
__asm("blx r0"); //jump to this address
Regards,
Lukas
Hi Lukas,
Thanks for your reply! Now i have another question, how to remap the interrupt vector table?
I have changed the xxx.ld file in the bootloader below, and i also set the register S32_SCB->VTOR = (uint32_t)0x8000 before jump to application from bootloader. But it seems that it didn't work.
MEMORY
{
/* Flash */
m_interrupts (RX) : ORIGIN = 0x00008000, LENGTH = 0x00000400
m_flash_config (RX) : ORIGIN = 0x00008400, LENGTH = 0x00000010
m_text (RX) : ORIGIN = 0x00008410, LENGTH = 0x0007FBF0 - 0x8000
/* SRAM_L */
m_data (RW) : ORIGIN = 0x1FFF8000, LENGTH = 0x00008000
/* SRAM_U */
m_data_2 (RW) : ORIGIN = 0x20000000, LENGTH = 0x00007000
}