使用STM32F103,从停止模式唤醒时调用以下函数进行时钟初始化,外部晶振故障的情况下,单片机多次唤醒后会有死机情况,怀疑是在外部晶振故障的情况下启动外部晶振,会有导致单片机死机的概率。请问有没有遇到这个问题或者清楚这个问题的老铁????????
void sysclocksetback(void)
{
__IO uint32_t StartUpCounter = 0,time_out=0x500,HES_status=0;
/*根据标志状态选择启动外部时钟*/
RCC_HSEConfig(RCC_HSE_ON);
while((HES_status==0)&&(StartUpCounter <= time_out))
{
HES_status=RCC_GetFlagStatus(RCC_FLAG_HSERDY);
StartUpCounter++;
}
if(HES_status)
{
/*使能时钟故障监测*/
RCC_ClockSecuritySystemCmd(ENABLE);
/*!< PLLCLK = 8MHz(HSE) * 6 = 48 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1,RCC_PLLMul_6);
/*使能pll*/
RCC_PLLCmd(ENABLE);
StartUpCounter=0;
while((RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==0)&&(StartUpCounter <= time_out))
{
StartUpCounter++;
}
/*选择pll做时钟源*/
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
StartUpCounter=0;
while((RCC_GetSYSCLKSource()!=0x08)&&(StartUpCounter <= time_out))
{
StartUpCounter++;
}
}
else
{
/*禁能时钟故障监测*/
RCC_ClockSecuritySystemCmd(DISABLE);
/*!< PLLCLK = 8MHz(HSI)/2 * 6 = 48 MHz */
RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_12);
/*使能pll*/
RCC_PLLCmd(ENABLE);
StartUpCounter=0;
while((RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==0)&&(StartUpCounter <= time_out))
{
StartUpCounter++;
}
/*选择pll做时钟源*/
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
StartUpCounter=0;
while((RCC_GetSYSCLKSource()!=0x08)&&(StartUpCounter <= time_out))
{
StartUpCounter++;
}
}
}
|