一、时钟源的基本概念
1.STM32 有5个时钟源:HSI、HSE、LSI、LSE、PLL。
HSI(High Speed Internal)是高速内部时钟,RC振荡器,频率为16MHz,精度不高。可以直接作为系统时钟或者用作PLL时钟输入。
HSE(High Speed External)是高速外部时钟,可接石英/陶瓷谐振器,或者接外部时钟源,频率范围为4MHz~26MHz。
LSI(Low Speed Internal)是低速内部时钟,RC振荡器,频率为32kHz,提供低功耗时钟。主要供独立看门狗和自动唤醒单元使用。
LSE(Low Speed External)是低速外部时钟,接频率为32.768kHz的石英晶体。RTC。
PLL为锁相环倍频输出。
2.系统时钟SYSCLK可来源于三个时钟源:
- HSI振荡器时钟
- HSE振荡器时钟
- PLL时钟
3.任何一个外设在使用之前,必须首先使能其相应的时钟。
二、STM32F4系列时钟树
三、RCC相关配置寄存器
typedef struct
{
__IO uint32_t CR;
__IO uint32_t PLLCFGR;
__IO uint32_t CFGR; /*!< RCC clock configuration register, Address offset: 0x08 */
__IO uint32_t CIR; /*!< RCC clock interrupt register, Address offset: 0x0C */
__IO uint32_t AHB1RSTR; /*!< RCC AHB1 peripheral reset register, Address offset: 0x10 */
__IO uint32_t AHB2RSTR; /*!< RCC AHB2 peripheral reset register, Address offset: 0x14 */
__IO uint32_t AHB3RSTR; /*!< RCC AHB3 peripheral reset register, Address offset: 0x18 */
uint32_t RESERVED0; /*!< Reserved, 0x1C */
__IO uint32_t APB1RSTR; /*!< RCC APB1 peripheral reset register, Address offset: 0x20 */
__IO uint32_t APB2RSTR; /*!< RCC APB2 peripheral reset register, Address offset: 0x24 */
uint32_t RESERVED1[2]; /*!< Reserved, 0x28-0x2C */
__IO uint32_t AHB1ENR; /*!< RCC AHB1 peripheral clock register, Address offset: 0x30 */
__IO uint32_t AHB2ENR; /*!< RCC AHB2 peripheral clock register, Address offset: 0x34 */
__IO uint32_t AHB3ENR; /*!< RCC AHB3 peripheral clock register, Address offset: 0x38 */
uint32_t RESERVED2; /*!< Reserved, 0x3C */
__IO uint32_t APB1ENR; /*!< RCC APB1 peripheral clock enable register, Address offset: 0x40 */
__IO uint32_t APB2ENR; /*!< RCC APB2 peripheral clock enable register, Address offset: 0x44 */
uint32_t RESERVED3[2]; /*!< Reserved, 0x48-0x4C */
__IO uint32_t AHB1LPENR; /*!< RCC AHB1 peripheral clock enable in low power mode register, Address offset: 0x50 */
__IO uint32_t AHB2LPENR; /*!< RCC AHB2 peripheral clock enable in low power mode register, Address offset: 0x54 */
__IO uint32_t AHB3LPENR; /*!< RCC AHB3 peripheral clock enable in low power mode register, Address offset: 0x58 */
uint32_t RESERVED4; /*!< Reserved, 0x5C */
__IO uint32_t APB1LPENR; /*!< RCC APB1 peripheral clock enable in low power mode register, Address offset: 0x60 */
__IO uint32_t APB2LPENR; /*!< RCC APB2 peripheral clock enable in low power mode register, Address offset: 0x64 */
uint32_t RESERVED5[2];
__IO uint32_t BDCR;
__IO uint32_t CSR;
uint32_t RESERVED6[2];
__IO uint32_t SSCGR;
__IO uint32_t PLLI2SCFGR;
__IO uint32_t PLLSAICFGR;
__IO uint32_t DCKCFGR;
} RCC_TypeDef;
四、RCC相关头文件和固件库源文件
1.时钟使能配置:
RCC_HSICmd, RCC_LSICmd, RCC_PLLCmd, RCC_PLLI2SCmd, RCC_PLLSAICmd, RCC_RTCCLKCmd,RCC_AHBxPeriphClockCmd
RCC_APBxPeriphClockCmd
2.时钟源和时钟相关配置:
RCC_HSEConfig, RCC_LSEConfig, RCC_PLLConfig, RCC_PLLI2SConfig, RCC_PLLSAIConfig, RCC_MCO1Config, RCC_MCO2Config, RCC_SYSCLKConfig, RCC_HCLKConfig,RCC_PCLK1Config,RCC_PCLK2Config,RCC_RTCCLKConfig,RCC_I2SCLKConfig
3.外设复位函数
RCC_AHB1PeriphResetCmd,RCC_AHB2PeriphResetCmd,RCC_AHB3PeriphResetCmd,RCC_APB1PeriphResetCmd,RCC_APB2PeriphResetCmd
4.状态参数获取参数:
RCC_GetSYSCLKSource,RCC_GetClocksFreq,RCC_GetFlagStatus,RCC_ClearFlag
5.RCC中断相关函数 :
RCC_ITConfig,RCC_ClearITPendingBit,RCC_GetITStatus
版权声明:本文为qq_44343584原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。