keaz128 bootloading

cancel
Showing results for 
Search instead for 
Did you mean: 

keaz128 bootloading

360 Views
Contributor II

Hello people. I try to make a custom bootloader for keaz128 MCU and got next trouble. I write jump to app function like this(got from example for other MCU):

void JumpToUserApplication(LWord userSP, LWord userStartup)
{
volatile LWord avoid_optimization;
avoid_optimization = userSP; //In order to avoid optimization issue when -Os
avoid_optimization = userStartup; //In order to avoid optimization issue when -Os
// set up stack pointer
__asm("msr msp, r0");
__asm("msr psp, r0");
// Jump to PC (r1)
__asm("mov pc, r1");
}
While i debug in i found what register R1 doesn't contatin userStartup value. I fix this problem and mcu jump to new area but it start execute interrup table as a code.

volatile uint32_t avoid_optimization, avoid_optimization2;
avoid_optimization = userSP;
avoid_optimization2 = userStartup;


// set up stack pointer
__asm("msr msp, r0");
__asm("msr psp, r0");

// Jump to PC (r1)
__asm("mov pc, r3");

No jump to startup code of new app. May be it's because of i don't relocate VTOR. But i didn't find it's address in MCU lib. I try change it using address(0xE000ED08) witch i get from other exaple but it didn't solve a trouble.

Do somebody know solution for this trouble?

0 Kudos
3 Replies

57 Views
NXP TechSupport
NXP TechSupport

Hi VITALI HARUDKA,

    Please check my attached code, you can refer to it, it is the UART bootloader for KEA128, it can works with the KBOOT2.0 kinetisflashtool.

  


Have a great day,
Kerry

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

0 Kudos

57 Views
Contributor II

I just copy code from my stm32f103 custom bootloader and it work
void Bootloader_GoToUserApp()
{
__disable_irq();
typedef void (*funcPtr)(void);
uint32_t jumpAddr = *(volatile uint32_t *)(APP_PROGRAM_START_ADDRESS + 0x04); /* reset ptr in vector table */

funcPtr usrMain = (funcPtr) jumpAddr;

SCB->VTOR = APP_PROGRAM_START_ADDRESS;

__set_MSP(*(__IO uint32_t*) APP_PROGRAM_START_ADDRESS);
__enable_irq();
usrMain(); /* go! */
}

0 Kudos

57 Views
Specialist V

Hi

You are probably incorrectly using the function call. You are presumably passing the address of the applications start (where its reset vector is located) whereby this routine requires you to pass the "values" that are there.

The code that you need (for Cortex-M4) if you pass the start address is:

extern void start_application(unsigned long app_link_location)
{
    asm(" ldr sp, [r0,#0]");                                             // load the stack pointer value from the program's reset vector
    asm(" ldr pc, [r0,#4]");                                             // load the program counter value from the program's reset vector to cause operation to continue from there
}

whereby you only need to pass the pointer to the application's reset vector location since the PC value is one long word further anyway.

In case of problems, there are boot loaders for your device at the links below, and the code is available for free in the Open Source version of the uTasker project. It solves all of the problems that are reported time and time again by developers doing such things and this allows you and others to save lots of time and potentially the industry to save millions in re-inventing the wheel over and over again.

Regards

Mark

http://www.utasker.com/docs/uTasker/uTaskerSerialLoader.PDF
http://www.utasker.com/kinetis.html
http://www.utasker.com/kinetis/TRK-KEA128.html
http://www.utasker.com/kinetis/FRDM-KEAZ128Q80.html

0 Kudos