STM32F103系统时钟配置
时钟树的理解确定分频倍频之后再做
STM32F103时钟树
假设外接晶振8MHz,现在需要配置出系统72MHz时,需要
配置代码(外部晶振8MHz配置系统时钟为72MHz)
/*RCC config*/
void RCC_Configuration(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
while(SUCCESS != RCC_WaitForHSEStartUp()){}
/*设置FLASH存储器延时时钟周期数*/
FLASH_SetLatency(FLASH_Latency_2); //FLASH_Latency_2 2延时周期
/*选择FLASH预取指缓存的模式*/
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // 预取指缓存使能
/*设置PLL时钟源及倍频系数*/
/* Fcpu = (PLL_src * PLL_MUL) = (8 Mhz / 1) * (9) = 72Mhz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/*检查指定的RCC标志位(PLL准备好标志)设置与否*/
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) {}
/* Set system clock dividers */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div2);
RCC_ADCCLKConfig(RCC_PCLK2_Div6);
/* Embedded Flash Configuration */
FLASH_SetLatency(FLASH_Latency_2);
FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable);
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/*SYSCLK configuration*/
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}
/*NVIC config*/
void NVIC_Configuration(void)
{
/* Configure and enable ADC interrupt */
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0);
/* Configure the NVIC Preemption Priority Bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
}
void bsp_init(void){
RCC_Configuration();
NVIC_Configuration();
SysTick_Config(72000); //1ms
}
上一篇:学习stm32f103(二) 关于系统时钟
下一篇:如何在MDK中查看系统时钟配置(stm32编程技巧小记)
推荐阅读最新更新时间:2024-03-16 16:07