STM32时钟初始化

void RCC_Configuration(void)
{
  RCC_DeInit();


  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);


  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();


  if(HSEStartUpStatus == SUCCESS)
  {
    /* ¸ßËÙHCLK  AHB1 = SYSCLK =PLLCLK*/
    RCC_HCLKConfig(RCC_SYSCLK_Div1); //AHB1
  
    /* ¸ßËÙPCLK2 AHB2= HCLK =PLLCLK*/
    RCC_PCLK2Config(RCC_HCLK_Div1); 


    /* µÍËÙ PCLK1 AHB1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);


    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);


    /* PLLCLK = 12MHz * 6 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6);



    /* Enable PLL */ 
    RCC_PLLCmd(ENABLE);


    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }


    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);


    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
 

}

STM32使用外部时钟,做个新项目有时外设时钟与以前设备不一样,往往忘了修改时钟设置,STM32很多功能照样可以运行,但是波特率肯定不正确

你可能感兴趣的:(CLK)