查看ST库函数代码发现:- /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration ---------------------------*/
- /* Enable HSE */
- RCC->CR |= ((uint32_t)RCC_CR_HSEON);
-
- /* Wait till HSE is ready and if Time out is reached exit */
- do
- {
- HSEStatus = RCC->CR & RCC_CR_HSERDY;
- StartUpCounter++;
- } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
- if ((RCC->CR & RCC_CR_HSERDY) != RESET)
- {
- HSEStatus = (uint32_t)0x01;
- }
- else
- {
- HSEStatus = (uint32_t)0x00;
- }
程序在使能外部晶振后,会有一个等待时间,等待外部晶振稳定后继续执行频率设置指令。但这个等待时间不是无限长的,有一个超时时间计数 HSE_STARTUP_TIMEOUT,超时之后就会默认外部晶振开启失败。
解决方法:库函数中HSE_STARTUP_TIMEOUT 的值定义为0x0500,通过将其增为0x0800后,系统时钟可设置成功。
|