My bootloader works correct, The application to be bootloaded works correct on it's own when is it programmed directly onto the micro. When I bootload the application with the bootloader and jump direct to the application from the bootloader I have the following problem:
(1) PIT time is wrong
Bootloader clock configuration (not use PIT ) :
void Sys_Init(void)
{
//Clk Out
MC_CGM.AC6_SC.R = 0x02000000; //Enable PLL0 - clkout0 //MC_CGM_AC6_SC
MC_CGM.AC6_DC0.B.DE = 1; //Enable divider for SYSCLK0
MC_CGM.AC6_DC0.B.DIV = 3; //Set divider for SYSCLK0 (div by 4)
//Configure RunPeripheralConfiguration regist ers in ME_RUN_PC0
MC_ME.RUN_PC[0].B.DRUN = 1; //Enable DRUN mode for all peripherals using ME_RUN_PC[0]
MC_ME.DRUN_MC.B.XOSCON = 1; //Enable external oscilator
//AUX Clock Selector 3 setup
MC_CGM.AC3_SC.B.SELCTL =0x01; //connect (8..40MHz) XTALL to the PLL0 input
MC_ME.DRUN_MC.B.PLL0ON = 1; //Enable PLL0 for DRUN mode
//AUX Clock Selector 0 setup
MC_CGM.AC0_SC.B.SELCTL=0x2; //source PLL0 PHI 200MHz
MC_CGM.AC0_DC0.R = 0x80010000; //MOTC_CLK enable with divider 1
MC_CGM.AC0_DC2.R = 0x80010000; //ADC_CLK enable with divider 1
// Set PLL0 to 200MHz
PLLDIG.PLL0CR.B.CLKCFG = 1; //Bypass mode PLL0 on
// RFDPHI1 = 10, RFDPHI = 2, PREDIV = 2, MFD = 14
PLLDIG.PLL0DV.R = 0x50000000 |0x00020000 |0x00002000 |0x0014 ; //predefined PLL0 divider register
//Mode transition to apply the PLL0 setup and set Normal mode with PLL running
MC_ME.MCTL.R = 0x30005AF0; //DRUN Mode & Key
MC_ME.MCTL.R = 0x3000A50F; //DRUN Mode & Key
while(!MC_ME.GS.B.S_PLL0); //ME_GS Wait for PLL stabilization.
while(MC_ME.GS.B.S_MTRANS); //Waiting for end of transaction
while(MC_ME.GS.B.S_CURRENT_MODE != DRUN_MODE); // ME_GS Check DRUN mode has successfully been entered
}//Sys_Init
Application clock configuration :
MC_ME.RUN_PC[0].R=0x000000FE;//
void Sys_Init_1(void)
{
MC_ME.RUN0_MC.R&=0xFFFFFF1F; //
/* Configure PLL0 to 160 MHz. */
PLLDIG.PLL0DV.B.RFDPHI1 = 4;
PLLDIG.PLL0DV.B.RFDPHI = 4;
PLLDIG.PLL0DV.B.PREDIV = 1;
PLLDIG.PLL0DV.B.MFD = 16;
//Fpll1_phi=80Mhz
PLLDIG.PLL1DV.B.RFDPHI = 10;
PLLDIG.PLL1DV.B.MFD = 10;
MC_CGM.AC3_SC.B.SELCTL=1;
MC_CGM.AC4_SC.B.SELCTL=3;
MC_CGM.SC_DC0.B.DIV = 3; /* Freq = sysclk / (3+1) = sysclk / /20MHZ
MC_CGM.SC_DC0.B.DE = 1; /* Enable divided clock */
MC_CGM.AC0_SC.B.SELCTL=0;
//MC_CGM.AC0_SC.B.SELCTL=1;
MC_CGM.AC0_DC0.R = 0x80000000|(AUX0_clk_DIV0 <<16);
MC_CGM.AC0_DC2.R=0x80010000;
MC_ME.RUN0_MC.R|=0x00000020; //
MC_ME.RUN0_MC.R|=0x00000040; /
MC_ME.RUN0_MC.R|=0x00000080; //
MC_ME.RUN0_MC.R|=0x00000004; //80M
MC_ME.MCTL.R = 0x40005AF0;
MC_ME.MCTL.R = 0x4000A50F;
while(MC_ME.GS.B.S_MTRANS == 1); /* Wait for mode transition complete */
while(MC_ME.GS.B.S_CURRENT_MODE!=4); //
}//Sys_Init
MC_ME.PCTL30.B.RUN_CFG = 0; // PIT
PIT_0.MCR.B.MDIS = 0; //
PIT_0.MCR.B.FRZ = 1; //
PIT0_init(1999999); // 100MS
PIT_0.MCR.B.FRZ = 0; //
I find that the clock of PIT is IRCOSC, I do this in bootloader when jump to application but it is not work.
Bootloader :
MC_ME.RUN_PC[1].B.DRUN =0;
MC_ME.PCTL30.B.RUN_CFG = 1;
PIT_0.MCR.B.MDIS = 1;
Hi,
I'm used to recommend these two things:
- either jump to the application right after reset
- or put everything back to default reset state in bootloader before jumping to the application.
This is 100% solution for all similar issues.
Regards,
Lukas