I have downloaded standard bootloader code from the nxp's website. Built the code and loaded into the Eval board.
It seems it is not jumping to application. Unable to trace the exact problem.
I have used following bootloader code. It will be helpful if anyone can comment into this.
Code:
#include "timeout.h"
#include "comm.h"
#include "clock.h"
/* Bootloader definitions */
/* Start address for the application received by the bootloader
* application vector table should start at this address
* */
#define APP_START_ADDRESS 0x1000
/* Global variables */
uint8_t boot_from_comm = 0; /* Used to signal activity on the comm channel */
/* Prototype */
void JumpToUserApplication( unsigned int userSP, unsigned int userStartup);
/* Main Application*/
int main(void)
{
/* Initialize clock */
clock_initi();
/* Initialize communication interfaces */
init_comm();
/* Initialize timeout */
init_timeout();
/* Check if boot start has been received or timeout occurred */
do{
uint8_t word_received = comm_status_rx();
if(word_received){
boot_from_comm = 1;
comm_download_app();
}
} while((!timeout()) & (!boot_from_comm));
/* Disable all systems and leave device as if coming out of reset */
disable_timeout();
disable_comm();
reset_clock();
/* Check if a valid application is loaded and jump to it */
JumpToUserApplication(*((uint32_t*)APP_START_ADDRESS), *((uint32_t*)(APP_START_ADDRESS + 4)));
/* Should never return from application code */
for (;;) {};
/* Never leave main */
return 0;
}
/**
* Used to jump to the entry point of the user application
* The Vector table of the user application must be located at 0x1000
*
* */
void JumpToUserApplication( unsigned int userSP, unsigned int userStartup)
{
/* Check if Entry address is erased and return if erased */
if(userSP == 0xFFFFFFFF){
return;
}
/* Set up stack pointer */
__asm("msr msp, r0");
__asm("msr psp, r0");
/* Relocate vector table */
S32_SCB->VTOR = (uint32_t)APP_START_ADDRESS;
/* Jump to application PC (r1) */
__asm("mov pc, r1");
}
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////