首页 > 代码库 > void RCC_Configuration(void)

void RCC_Configuration(void)

void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
    RCC_DeInit();  //时钟管理重置  /* RCC system reset(for debug purpose) */
    RCC_HSEConfig(RCC_HSE_ON); //打开外部晶振  //Enable HSE
    HSEStartUpStatus = RCC_WaitForHSEStartUp();  //等待外部晶振就绪  //Wait till HSE is ready
    if(HSEStartUpStatus == SUCCESS)
    {
        RCC_HCLKConfig(RCC_SYSCLK_Div1);    //AHB使用系统时钟   //HCLK = SYSCLK
        RCC_PCLK2Config(RCC_HCLK_Div1);     //APB2为HCLK/1      //PCLK2 = HCLK/1
        RCC_PCLK1Config(RCC_HCLK_Div2);     //APB1为HCLK/2      //PCLK1 = HCLK/2
        RCC_ADCCLKConfig(RCC_PCLK2_Div4);   //设置ADC时钟频率
        //注:AHB主要负责外部存储器时钟。PB2负责AD,I/O,高级TIM,串口1。APB1负责DA,USB,SPI,I2C,CAN,串口2345,普通TIM。
        FLASH_SetLatency(FLASH_Latency_2);  //flash操作的延时   //Flash 2 wait state
        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);   //flash读取缓冲,加速 //Enable Prefetch Buffer
     
        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);  //PLLCLK = 8MHz * 9 = 72MHz
        RCC_PLLCmd(ENABLE);  //启动PLL //Enable PLL
        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) //等待PLL启动  /* Wait till PLL is ready */
        {
        }
        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //将PLL设置为系统时钟源  /* Select PLL as system clock source */
        while(RCC_GetSYSCLKSource() != 0x08)           //等待系统时钟源的启动  /* Wait till PLL is used as system clock source */
        {
        }
    }