KL26 Bootloader Jump

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

KL26 Bootloader Jump

852 Views
Mike_d
Contributor IV

Hello,

I've got a KL26 and I'm trying to get my bootloader to jump to the application. Can you show me the procedures in C and how to verify they are working correctly?

Thanks,

-Mike

0 Kudos
3 Replies

399 Views
pavel_krenek
NXP Employee
NXP Employee

Hi Mike,

I am the author of bootloader AN2295 for Kinetis.  When you jump to the application from the bootloader you need to be sure that SP - stack pointer is initialized after that the procedure is only to put the startup address of your application to the PC (program counter). You can put short assembler code into the C function as was mentioned.

Best regards,

Pavel

0 Kudos

399 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Michael,

There is a DOC about the bootloader of KL26, it introduce the process

and how to jump application clearly , i think you can refer to it .

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

399 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi Michael

If you want to jump to your application, you should be sure of the memory allocation, the memory address of your app and the interrupt vector table.

The next image show an example of memory map

Capture.2PNG.PNG

For more information about the memory distribution and the protocol see the next application note

http://cache.nxp.com/files/microcontrollers/doc/app_note/AN2295.pdf

To be sure in which mode the uC is, you should ask of the status and decide if you want to jump to the application.

// read the srs register

  if(SRS_REG & SRS_POR_MASK)

    enableBootMode = 1;

.   // Bootloader protocol runs !

After that you will jump to the application sending parameters the stack pointer and the program counter and do some assembly instructions

    // Jump to user application

    JumpToUserApplication(*((unsigned long*)RELOCATED_VECTORS), *((unsigned long*)(RELOCATED_VECTORS+4))); 

void JumpToUserApplication(LWord userSP, LWord userStartup)

{

  // set up stack pointer

  __asm("msr msp, r0");

  __asm("msr psp, r0");

  // Jump to PC (r1)

  __asm("mov pc, r1");

}

For more details, please check this document

https://community.freescale.com/docs/DOC-330712

Also, there is an USB Bootloader that is similar than the other one, provides different architecture for the bootloader, but needs the same memory distribution.

And for be sure if you want to jump to the application.

static void Switch_mode(void)

{

/* Body */

volatile uint_32  temp = 1; /* default the button is not pressed */

/* Get PC and SP of application region */

New_sp  = IMAGE_ADDR[0];

New_pc  = IMAGE_ADDR[1];

if(temp)

{

if((New_sp != 0xffffffff)&&(New_pc != 0xffffffff))

{

            asm

            {

                ldr   r4,=New_sp

                ldr   sp, [r4]

                ldr   r4,=New_pc

                ldr   r5, [r4]

                blx   r5

            }

}

You already have the image address for the stack pointer and the program counter, you verify that the address are correct and if exist a code for application and then you load to the SP and PC in an assembly way.

Hope it helps

Mario

0 Kudos