S32K144 bootloader jump into application

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

S32K144 bootloader jump into application

6,539 Views
jimfung
Contributor III

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

6 Replies

3,399 Views
stanish
NXP Employee
NXP Employee

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.

3,399 Views
MehmetKirgozoglu
Contributor I

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;

        PUBWEAK Reset_Handler
        SECTION .text:CODE:REORDER:NOROOT(2)
Reset_Handler
        CPSID   I               ; Mask interrupts
        LDR     R0, =0xE000ED08
        LDR     R1, =__vector_table
        STR     R1, [R0]
        LDR     R2, [R1]
        MSR     MSP, R2
        LDR     R0, =SystemInit
        BLX     R0
        CPSIE   I               ; Unmask interrupts
        LDR     R0, =__iar_program_start
        BX      R0

What do you think is the reason, where am I doing wrong? I would be glad if you help. Thank you.

0 Kudos

3,399 Views
stanish
NXP Employee
NXP Employee

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

0 Kudos

3,400 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

    __asm("ldr r0,=main");   //load address of main function (use any address you need)
    __asm("blx r0");   //jump to this address

Regards,

Lukas

0 Kudos

3,400 Views
jimfung
Contributor III

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
}

0 Kudos

3,399 Views
eautopower
Contributor IV

kim:

 could you tell me how to jump to APP,this is my e_mail xiexingying@eautopower.com

thank you !

0 Kudos