看datasheet的说法:
After the CPU enters sleep mode, it can be woken up by:
1. External interrupt
2. RTC/USB interrupt
3. External reset
When an oscillator chip is used as the clock source for the STR91xFA, the CPU wakes up
from sleep mode following any of the above three input events. If a crystal is used as the
clock source, the crystal is disabled in sleep mode to save power consumption. When a
wakeup event occurs, the crystal does not recover fast enough and the CPU hangs.
Workarounds
Workaround solutions include:
1. Use the 32 kHz RTC clock as the clock source for sleep mode:
a) Select the RTC clock as the CPU clock source prior entering sleep mode.
b) The CPU wakes up following any of the three wakeup events and waits for the
crystal to start oscillation. A crystal startup time is about 1.5 ms typical.
c) After the crystal wakes up, the CPU waits for a tWAIT time before the first code is
fetched from Flash memory. The software can then change the CPU clock source
back to the OSC or PLL clock. The duration of tWAIT depends on the crystal
frequency. tWAIT equals 50 µs at 25 MHz and 312 µs at 4 MHz.
2. Instead of a crystal, use an oscillator as STR91xFA clock source.
This limitation will not be fixed in future silicon revisions
SCU_MCLKSourceConfig(SCU_MCLK_OSC);
// Set the PLL's multipliers and dividers
SCU_PLLFactorsConfig(BSP_PLL_N, BSP_PLL_M, BSP_PLL_P);
SCU_PLLCmd(ENABLE); // Enable the PLL
SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // Set RCLK, the CPU clock's main divider
SCU_PCLKDivisorConfig(SCU_PCLK_Div1); // Set APBDIV, the PCLK divider
SCU_FMICLKDivisorConfig(SCU_FMICLK_Div2);
SCU_MCLKSourceConfig(SCU_MCLK_PLL); // Select the PLL output as CPU clock
}
void SysClkRTCConfig(void)
{
//SCU_MCLKSourceConfig(SCU_MCLK_RTC);
// Set the PLL's multipliers and dividers
// SCU_PLLFactorsConfig(BSP_PLL_N, BSP_PLL_M, BSP_PLL_P);
SCU_PLLCmd(DISABLE); // Enable the PLL
SCU_MCLKSourceConfig(SCU_MCLK_RTC);
SCU_RCLKDivisorConfig(SCU_RCLK_Div1); // Set RCLK, the CPU clock's main divider ,RClk=Fmstr
SCU_PCLKDivisorConfig(SCU_PCLK_Div1); // Set APBDIV, the PCLK divider
SCU_FMICLKDivisorConfig(SCU_FMICLK_Div1);
SCU_MCLKSourceConfig(SCU_MCLK_RTC);
//SCU_MCLKSourceConfig(SCU_MCLK_PLL); // Select the PLL output as CPU clock
每次准备sleep,调用以下函数
void LPMode_Sleep_ExternalWakeUP_Interrupt_LVD_OFF_PWD_OFF(void)
{
/*External wake up interrupt configuration on EXINT2 line 16 */
//ExternalWakeUP_Interrupt_Config();
/*The system clock source switched to the RTC clock */
SCU_MCLKSourceConfig(SCU_MCLK_RTC); /* this line is used when a crystal is
connected to the CPU crystal inputs*/
/*Enter Sleep mode*/
SCU_EnterSleepMode();
/*Dummy instructions*/
asm_func_Sleep();
/*Switch to oscillator as clock source after wake up*/
SCU_MCLKSourceConfig(SCU_MCLK_OSC);
// Clock_Source(PLL_Clk66);
}