|
求助: STM32F4外部低速晶振LSE不起振,通过测试,卡死在 while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET), 最终会return HAL_TIMEOUT;求助这是什么原因导致呢?
还有求教32.768KHZ外部低速晶振,是上电就会震荡嘛,晶振震荡和软件有没有配置没关系吧?
卡死程序如下:
/* Set the new LSE configuration -----------------------------------------*/
__HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
/* Check the LSE State */
if((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
{
/* Get Start Tick*/
tickstart = HAL_GetTick();
/* Wait till LSE is ready */
while(__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == RESET)
{
if((HAL_GetTick() - tickstart ) > RCC_LSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
}
由下面函数调用:
void SystemClock_HSI_LSE_Init(u32 pllm,u32 plln,u32 pllp,u32 pllq)
{
HAL_StatusTypeDef ret = HAL_OK;
RCC_OscInitTypeDef RCC_OscInitStructure;
RCC_ClkInitTypeDef RCC_ClkInitStructure;
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};//
__HAL_RCC_PWR_CLK_ENABLE(); //使能PWR时钟
//下面这个设置用来设置调压器输出电压级别,以便在器件未以最大频率工作
//时使性能与功耗实现平衡。
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);//设置调压器输出电压级别1
//RCC_OscInitStructure.OscillatorType=RCC_OSCILLATORTYPE_HSE; //时钟源为HSE
RCC_OscInitStructure.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;//add 20220629 增加LSI,用于RTC时钟;
RCC_OscInitStructure.LSEState = RCC_LSE_ON;//add 20220629 开启LSE
RCC_OscInitStructure.LSIState = RCC_LSI_OFF;//add 20220629 关闭LSI
RCC_OscInitStructure.HSEState = RCC_HSE_OFF; //关闭HSE 20221028
RCC_OscInitStructure.HSIState = RCC_HSI_ON; //打开HSI 20221028
RCC_OscInitStructure.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; // 20221028
RCC_OscInitStructure.PLL.PLLState = RCC_PLL_ON;//打开PLL
RCC_OscInitStructure.PLL.PLLSource = RCC_PLLSOURCE_HSI;//PLL时钟源选择HSI
RCC_OscInitStructure.PLL.PLLM=pllm; //主PLL和音频PLL分频系数(PLL之前的分频),取值范围:2~63.
RCC_OscInitStructure.PLL.PLLN=plln; //主PLL倍频系数(PLL倍频),取值范围:64~432.
RCC_OscInitStructure.PLL.PLLP=pllp; //系统时钟的主PLL分频系数(PLL之后的分频),取值范围:2,4,6,8.(仅限这4个值!)
RCC_OscInitStructure.PLL.PLLQ=pllq; //USB/SDIO/随机数产生器等的主PLL分频系数(PLL之后的分频),取值范围:2~15.
ret=HAL_RCC_OscConfig(&RCC_OscInitStructure);//初始化
if(ret!=HAL_OK) while(1);
程序卡死在, if(ret!=HAL_OK) while(1);不往下执行
附录硬件图:
|
-
|