为什么我连仿真器下载程序后第一次运行没有问题,每次拔下仿真器重新上电后老是丢失系统时钟,进入limp mode
时钟配置代码:
while(SysCtrlRegs.PLLSTS.bit.MCLKSTS != 0)
{
DelayUs(20);
SysCtrlRegs.PLLSTS.bit.MCLKCLR = 1;
}
// Make sure the PLL is not running in limp mode
if (SysCtrlRegs.PLLSTS.bit.MCLKSTS != 1)
{ // PLL is not running in limp mode
SysCtrlRegs.PLLSTS.bit.MCLKOFF = 1; // Turn off missing clock detect before changing PLLCR
SysCtrlRegs.PLLSTS.bit.DIVSEL = 0; // DIVSEL must be 0 or 1 (/4 CLKIN mode) before changing PLLCR
SysCtrlRegs.PLLCR.bit.DIV = 0x000A; // PLLx10/4 (because DIVSEL is /4)
// Wait for PLL to lock.
// During this time the CPU will run at OSCCLK/2 until the PLL is stable.
// Once the PLL is stable the CPU will automatically switch to the new PLL value.
// Code is not required to sit and wait for the PLL to lock. However,
// if the code does anything that is timing critical (e.g. something that
// relies on the CPU clock frequency to be at speed), then it is best to wait
// until PLL lock is complete. The watchdog should be disabled before this loop
// (e.g., as was done above), or fed within the loop.
while(SysCtrlRegs.PLLSTS.bit.PLLLOCKS != 1) // Wait for PLLLOCKS bit to set
{
//SysCtrlRegs.WDKEY = 0x0055; // Service the watchdog while waiting
//SysCtrlRegs.WDKEY = 0x00AA; // in case the user enabled it.
}
// After the PLL has locked, we are running in PLLx10/4 mode (since DIVSEL is /4).
// We can now enable the missing clock detect circuitry, and also change DIVSEL
// to /2. In this example, I will wait a bit of time to let inrush currents settle,
// and then change DIVSEL from /4 to /2. This is only an example. The amount of
// time you need to wait depends on the power supply feeding the DSP (i.e., how much
// voltage droop occurs due to the inrush currents, and how long it takes the
// voltage regulators to recover).
SysCtrlRegs.PLLSTS.bit.MCLKOFF = 0; // Enable missing clock detect circuitry
DelayUs(20/2); // Wait 20 us (just an example). Remember we're running
// at half-speed here, so divide function argument by 2.
SysCtrlRegs.PLLSTS.bit.DIVSEL = 0x2; // Change to /2 mode
}
else
{ // PLL is running in limp mode
// User should replace the below with a call to an appropriate function,
// for example shutdown the system (since something is very wrong!).
asm(" ESTOP0");
}