以8MHz外部晶振配置STM32F103为例(结合STM32CubeMX)
1.打开 \drivers\stm32f1xx_hal_conf.h 修改其中的宏定义为外部晶振频率:
#define HSE_VALUE ((uint32_t)8000000U)
2.打开 \drivers\board.h 修改以下宏:
#define BSP_CLOCK_SOURCE ("HSE") //HSI:内部时钟源默认, HSE:外部时钟源
#define BSP_CLOCK_SOURCE_FREQ_MHZ ((int32_t)8) //外部时钟参数:默认0,根据晶振实际设置
#define BSP_CLOCK_SYSTEM_FREQ_MHZ ((int32_t)72) //主频
3.采用STM32CubeMX配置时钟并得到SystemClock_Config()函数,打开rt-thread中 /drivers/drv_clk.c 找到system_clock_config函数,并修改该函数中和RCC_OscInitStruct相关的代码
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;