Hi CrasyCat,
Yes, you are right in that the bootloader is started first and after it finishes its configuration job (mainly to determine mode of operation), it either remains in bootloader mode or starts the application.
For the application to jump back to bootloader mode, we trigger a reset so if you think about it the application never actually "jumps" back to the bootloader and so there is no need to take care of the local and global variables inside of the bootloader.
I guess the pressing question here is that, if I were to use the approach of have two applications, how do i determine the _Startup adderess of the application so that the bootloader correctly jumps to it?
In the library model, the following was done:
void (* volatile const _UserEntry[])()@0xFABC={
0x9DCC, // asm NOP(9D), asm JMP(CC)
_Startup
};
#pragma CODE_SEG Bootloader_ROM
void Bootloader_Main(void);
void _Entry(void) {
PTGD = 0x00;
PTGDD = 0xF0; //PTG0-3 used for KBI input
PTGPE = 0x0F; //Pull-up enable
// MCG clock initialization, fBus=24MHz
MCGC2 = 0x36;
while(!(MCGSC & 0x02)); //wait for the OSC stable
MCGC1 = 0x1B;
MCGC3 = 0x48;
while ((MCGSC & 0x48) != 0x48); //wait for the PLL is locked
// Flash clock
FCDIV=0x4E; // PRDIV8=1; DIV[5:0]=14, flash clock should be 150-200kHz
// bus clock=24M, flash clock=fbus/8/(DIV[5:0]+1)
// bus clock=24M, flash clock=fbus/8/(DIV[5:0]+1)
if(!PTGD_PTGD0)
{
SOPT1 = 0x20; // disable COP only if bootloader mod is requested
// PTG0 is pressed
USBCTL0=0x44;
Bootloader_Main(); // Bootloader mode
}
else
asm JMP _UserEntry; // Enter User mode
}
#pragma CODE_SEG default
Thanks,
John