void SystemClock_Config(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON); //INPUT HSE = 24M
ErrorStatus HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
FLASH_PrefetchBufferCmd(ENABLE); //M0 defined
FLASH_SetLatency(FLASH_Latency_1); //M0 defined
RCC_PREDIV1Config(RCC_PREDIV1_Div1);
RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_2); //PLL CLK = HSE *RCC_PLLSource_PREDIV1*2 = 48M
RCC_PLLCmd(ENABLE); //enable PLL CLK
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) //WAIT PLL CLK ready
{
}
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //SELECT SYSCLK = PLLCLK =48M
// * - 0x00: HSI used as system clock
// * - 0x04: HSE used as system clock
// * - 0x08: PLL used as system clock
// * - 0x0C: HSI48 used as system clock, applicable only for STM32F072 devices
while(RCC_GetSYSCLKSource()!=0x08)
{
}
RCC_HCLKConfig(RCC_SYSCLK_Div1); //AHB CLK(HCLK) = SYS CLK = 48M
RCC_PCLKConfig(RCC_HCLK_Div1); //APB CLK(PCLK) = HCLK = 48M
RCC_USARTCLKConfig(RCC_USART1CLK_PCLK); // UART2 CLK = 48M
RCC_USARTCLKConfig(RCC_USART2CLK_PCLK); // UART2 CLK = 48M
RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); // I2C CLK =48M
RCC_USBCLKConfig(RCC_USBCLK_PLLCLK); // USB CLK = 48M
}
}
上一篇:STM32外部晶振8M更改为25M
下一篇:STM32使用16M外部晶振时出现异常
推荐阅读最新更新时间:2024-03-16 16:11