首页 > 代码库 > 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 */
{
}
}
}
{
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 */
{
}
}
}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。