My device is MK64FN1M0VMD12.The hardware is TWR-K64F120M. My compiler is IAR 7.2.
I have write a bootloader.
There are two parts for my program.
Boot loader 1 | |
INTERRUPT VECTOR TABLE | 1KB($00000000-$000003FF) |
NONVOLATILE REGISTERS(FLASH CONFIGURATION) | 16 bytes ($00000400-$0000040F) |
BOOT LOADER 1 | 3056 bytes($00000410-$00000FFF) |
Boot loader 2 | |
RELOCATED INTERRUPT VECTOR TABLE | 1KB($00001000-$000013FF) |
BOOT LOADER 2 | 31KB($00001400-$00008FFF) |
I write the program in the Boot loader 1 to jump to Boot loader 2.
#define RELOCATED_VECTORS 0x1000
SCB_VTOR =
RELOCATED_VECTORS;
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");
}
Before I adding the source code(as follow shown). The Boot loader 1 jumps to Boot loader 2 normally.
__root const unsigned char FlashCheck1_user @ 0x2fff ;
__root const unsigned char FlashCheck2_user @ 0x4fff;
__root const unsigned char FlashCheck3_user @ 0x6fff;
__root const unsigned char FlashCheck4_user @ 0x8fff;
After I adding the source code(as follow above). The Boot loader 1 can not jumps to Bootloader 2 normally.
Sometimes the program runs normally.But sometimes the program cannot run normally.It stops in
the source code(as shown below) of Boot loader 2.
while((MCG->S & MCG_S_LOCK0_MASK) == 0x00U) { /* Wait
until PLL is locked*/ }
Can anyone tell me the reason? Thank you very much.
Hi
If your boot loader (1) configures the PLL you may need to be sure that the code in the application (boot loader 2) used to configure it (again) doesn't 'assume' that the PLL control (clock state) is in its reset state. It needs to be able to handle starting in one of the other clock states.
Therefore I would review the PLL configuration code in the application to see whether it can reliably handle thiks.
Regards
Mark
P.S. If the boot loader (1) is configuring the PLL to the frequency needed by the apllication the application doesn't need any PLL configuration code of its own.