STM32F1一种相对简单的使用HSI配置系统时钟为64MHz的方法

【STM32F1一种相对简单的使用HSI配置系统时钟为64MHz的方法】最近因为项目成本需要,必须使用片内晶振作为系统的时钟源,所以对正点原子的项目模板时钟配置做了一些修改。使时钟倍频至64MHz供系统使用。
有需要的同学可以参考一下,代码如下:

#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL) /* #define SYSCLK_FREQ_HSEHSE_VALUE */ #define SYSCLK_FREQ_24MHz24000000 #else /* #define SYSCLK_FREQ_HSEHSE_VALUE */ /* #define SYSCLK_FREQ_24MHz24000000 */ /* #define SYSCLK_FREQ_36MHz36000000 */ /* #define SYSCLK_FREQ_48MHz48000000 */ /* #define SYSCLK_FREQ_56MHz56000000 */ /* #define SYSCLK_FREQ_72MHz72000000 */ #endif

这里先将宏定义注释掉;
#ifdef SYSCLK_FREQ_HSE uint32_t SystemCoreClock= SYSCLK_FREQ_HSE; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_24MHz uint32_t SystemCoreClock= SYSCLK_FREQ_24MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_36MHz uint32_t SystemCoreClock= SYSCLK_FREQ_36MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_48MHz uint32_t SystemCoreClock= SYSCLK_FREQ_48MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_56MHz uint32_t SystemCoreClock= SYSCLK_FREQ_56MHz; /*!< System Clock Frequency (Core Clock) */ #elif defined SYSCLK_FREQ_72MHz uint32_t SystemCoreClock= SYSCLK_FREQ_72MHz; /*!< System Clock Frequency (Core Clock) */ #else /*!< HSI Selected as System Clock source */ //uint32_t SystemCoreClock= HSI_VALUE; /*!< System Clock Frequency (Core Clock) */ uint32_t SystemCoreClock= 64000000; #endif

接着将SystemCoreClock替换为64MHz;
/*使用内部RC振荡器,设置系统时钟为64MHz*/ static void Intn_RC_Init(void) { RCC_DeInit(); RCC_HSICmd(ENABLE); while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY)== RESET); RCC_HCLKConfig(RCC_SYSCLK_Div1); //设置AHB时钟(HCLK) = 系统时钟 RCC_PCLK2Config(RCC_HCLK_Div1); //设置AHB2时钟 = HCLK RCC_PCLK1Config(RCC_HCLK_Div1); //设置AHB1时钟 = HCLK FLASH_SetLatency(FLASH_Latency_2); //设置FLASH存储器延时时钟周期数 FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_16); //设置PLL时钟源及倍频系数,频率为8/2*16=64MHz RCC_PLLCmd(ENABLE); while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); while(RCC_GetSYSCLKSource() != 0x08); }

这样就完成了系统时钟的配置!

    推荐阅读