资深版主
- 积分
- 10541
- 金钱
- 10541
- 注册时间
- 2017-2-18
- 在线时间
- 1908 小时
|
本帖最后由 peng1554 于 2018-11-15 11:58 编辑
原子这边F103板子(战舰V3、精英和MINIV3)主要用的是标准库。且外部高速晶振用的是8M。在标准库中提供了设置系统主时钟为24M,32M,48M,56M和72M的方法,例程原先用的72M作为系统主时钟
那么设置24M,32M,48M,56M该怎么设置呢?
改宏定义
官方的system_stm32f10x.c文件提供了方法,以战舰V3设置系统主时钟位56M为例
在system_stm32f10x.c中,我们注释掉SYSCLK_FREQ_HSE、SYSCLK_FREQ_24MHz、SYSCLK_FREQ_36MHz、SYSCLK_FREQ_48MHzh和SYSCLK_FREQ_72MHz
[mw_shl_code=c,true]#if defined (STM32F10X_LD_VL) || (defined STM32F10X_MD_VL) || (defined STM32F10X_HD_VL)
/* #define SYSCLK_FREQ_HSE HSE_VALUE */
#define SYSCLK_FREQ_24MHz 24000000
#else
/* #define SYSCLK_FREQ_HSE HSE_VALUE */
/* #define SYSCLK_FREQ_24MHz 24000000 */
/* #define SYSCLK_FREQ_36MHz 36000000 */
/* #define SYSCLK_FREQ_48MHz 48000000 */
#define SYSCLK_FREQ_56MHz 56000000
//#define SYSCLK_FREQ_72MHz 72000000
#endif[/mw_shl_code]
因为有定义SYSCLK_FREQ_56MHz。所以会将SYSCLK_FREQ_56MHz赋值给SystemCoreClock
[mw_shl_code=c,true]#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) */
#endif[/mw_shl_code]
也会编译SetSysClockTo56()函数
[mw_shl_code=c,true]#ifdef SYSCLK_FREQ_HSE
static void SetSysClockToHSE(void);
#elif defined SYSCLK_FREQ_24MHz
static void SetSysClockTo24(void);
#elif defined SYSCLK_FREQ_36MHz
static void SetSysClockTo36(void);
#elif defined SYSCLK_FREQ_48MHz
static void SetSysClockTo48(void);
#elif defined SYSCLK_FREQ_56MHz
static void SetSysClockTo56(void);
#elif defined SYSCLK_FREQ_72MHz
static void SetSysClockTo72(void);
#endif[/mw_shl_code]
而SetSysClockTo56()就是将系统主时钟设置为56M,该函数最主要的地方是这两处
[mw_shl_code=c,true] /* HCLK = SYSCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
/* PCLK2 = HCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
/* PCLK1 = HCLK */
RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;[/mw_shl_code]
[mw_shl_code=c,true] /* PLL configuration: PLLCLK = HSE * 7 = 56 MHz */
RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_HSE | RCC_CFGR_PLLMULL7);[/mw_shl_code]
经过上面的设置SYSCLK=56M,HCLK时钟=56M,APB1时钟=28M,APB2时钟=56M
|
|