赞
踩
本文以外部高速时钟源HSE为例,介绍STM32F4时钟配置实现。
STM32F4时钟树如下图所示:
上图(上图中的180Mhz改为168Mhz)中红色箭头线时钟传播路径,紫色框标注的是重要的时钟配置对象,包括:AHB bus、Core、memory 、DMA、APB peripheral 和 APB timer。下面介绍实现方法。
注:AHB最大允许时钟频率为168MHz,APB2最大为84MHz,APB1最大为42MHz。
STM32F4时钟系统初始化是在system_stm32f4xx.c中完成的。首先
1、全部配置如下:
- This file configures the system clock as follows:
- *=============================================================================
- *=============================================================================
- * Supported STM32F40xxx/41xxx devices
- *-----------------------------------------------------------------------------
- * System Clock source | PLL (HSE)
- *-----------------------------------------------------------------------------
- * SYSCLK(Hz) | 168000000
- *-----------------------------------------------------------------------------
- * HCLK(Hz) | 168000000
- *-----------------------------------------------------------------------------
- * AHB Prescaler | 1
- *-----------------------------------------------------------------------------
- * APB1 Prescaler | 4
- *-----------------------------------------------------------------------------
- * APB2 Prescaler | 2
- *-----------------------------------------------------------------------------
- * HSE Frequency(Hz) | 8000000
- *-----------------------------------------------------------------------------
- * PLL_M | 8
- *-----------------------------------------------------------------------------
- * PLL_N | 336
- *-----------------------------------------------------------------------------
- * PLL_P | 2
- *-----------------------------------------------------------------------------
- * PLL_Q | 7
- *-----------------------------------------------------------------------------
- * PLLI2S_N | NA
- *-----------------------------------------------------------------------------
- * PLLI2S_R | NA
- *-----------------------------------------------------------------------------
- * I2S input clock | NA
- *-----------------------------------------------------------------------------
- * VDD(V) | 3.3
- *-----------------------------------------------------------------------------
- * Main regulator output voltage | Scale1 mode
- *-----------------------------------------------------------------------------
- * Flash Latency(WS) | 5
- *-----------------------------------------------------------------------------
- * Prefetch Buffer | ON
- *-----------------------------------------------------------------------------
- * Instruction cache | ON
- *-----------------------------------------------------------------------------
- * Data cache | ON
- *-----------------------------------------------------------------------------
- * Require 48MHz for USB OTG FS, | Disabled
- * SDIO and RNG clock |
- *-----------------------------------------------------------------------------
- *=============================================================================
2、PLL配置
- #if defined(STM32F40_41xxx) || defined(STM32F427_437xx) || defined(STM32F429_439xx) || defined(STM32F401xx) || defined(STM32F469_479xx)
- /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLL_M) * PLL_N */
- #define PLL_M 8
- #elif defined(STM32F412xG) || defined(STM32F413_423xx) || defined (STM32F446xx)
- #define PLL_M 8
- #elif defined (STM32F410xx) || defined (STM32F411xE)
- #if defined(USE_HSE_BYPASS)
- #define PLL_M 8
- #else /* !USE_HSE_BYPASS */
- #define PLL_M 16
- #endif /* USE_HSE_BYPASS */
- #else
- #endif /* STM32F40_41xxx || STM32F427_437xx || STM32F429_439xx || STM32F401xx || STM32F469_479xx */
-
- /* USB OTG FS, SDIO and RNG Clock = PLL_VCO / PLLQ */
- #define PLL_Q 7
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。