STM32时钟学习之STM3210X_RCC.H解读
扫描二维码
随时随地手机看文章
当HSI被用于作为PLL时钟的输入时,系统时钟能得到的最大频率是64MHZ。
STM3210X_RCC.H头文件,主要是对RCC相关的寄存器进行了一个重新的定义命名以及对.c文件中的函数进行申明。
可以从参考手册的6.3 RCC寄存器描述了解到。更加详细的内容
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name : stm32f10x_rcc.h
* Author : MCD Application Team
* Version : V2.0.2
* Date : 07/11/2008
* Description : This file contains all the functions prototypes for the
* RCC firmware library.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32F10x_RCC_H
#define __STM32F10x_RCC_H
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_map.h"
/* Exported types ------------------------------------------------------------*/
typedef struct
{
u32 SYSCLK_Frequency;
u32 HCLK_Frequency;
u32 PCLK1_Frequency;
u32 PCLK2_Frequency;
u32 ADCCLK_Frequency;
}RCC_ClocksTypeDef; //定义结构体
/* Exported constants --------------------------------------------------------*/
/* HSE configuration */
/********RCC_CR时钟控制寄存器***********
第16位:HSE ON 外部高速时钟使能
0:HSE振荡器关闭
1:HSE振荡器开启
第18位:HSEBYP 外部高速时钟旁路
0:外部4-16MHZ振荡器没有旁路
1:外部4-16MHZ外部晶体振荡器被旁路
***************END**********************/
#define RCC_HSE_OFF ((u32)0x00000000)
#define RCC_HSE_ON ((u32)0x00010000)
#define RCC_HSE_Bypass ((u32)0x00040000)
#define IS_RCC_HSE(HSE) (((HSE) == RCC_HSE_OFF) || ((HSE) == RCC_HSE_ON) ||
((HSE) == RCC_HSE_Bypass))
/* PLL entry clock source */
/********RCC_CFGR时钟配置寄存器***********
第16位:PLLSRC PLL输入时钟源
0:HSI振荡器时钟经2分频后作为PLL输入时钟
1:HSE时钟作为PLL输入时钟
第17位:PLLXTPRE HSE分频器作为PLL输入
0:HSE 不分频
1:HSE 2分频
***************END**********************/
#define RCC_PLLSource_HSI_Div2 ((u32)0x00000000)
#define RCC_PLLSource_HSE_Div1 ((u32)0x00010000)
#define RCC_PLLSource_HSE_Div2 ((u32)0x00030000)
#define IS_RCC_PLL_SOURCE(SOURCE) (((SOURCE) == RCC_PLLSource_HSI_Div2) ||
((SOURCE) == RCC_PLLSource_HSE_Div1) ||
((SOURCE) == RCC_PLLSource_HSE_Div2))
/* PLL multiplication factor */
/********RCC_CFGR时钟配置寄存器***********
第21:18位:PLLMUL PLL倍频系数
由软件设置来确定PLL倍频系数,只有在PLL关闭的情况下才能被写入
注意:PLL的输出频率不能超过72MHZ
***************END**********************/
#define RCC_PLLMul_2 ((u32)0x00000000)
#define RCC_PLLMul_3 ((u32)0x00040000)
#define RCC_PLLMul_4 ((u32)0x00080000)
#define RCC_PLLMul_5 ((u32)0x000C0000)
#define RCC_PLLMul_6 ((u32)0x00100000)
#define RCC_PLLMul_7 ((u32)0x00140000)
#define RCC_PLLMul_8 ((u32)0x00180000)
#define RCC_PLLMul_9 ((u32)0x001C0000)
#define RCC_PLLMul_10 ((u32)0x00200000)
#define RCC_PLLMul_11 ((u32)0x00240000)
#define RCC_PLLMul_12 ((u32)0x00280000)
#define RCC_PLLMul_13 ((u32)0x002C0000)
#define RCC_PLLMul_14 ((u32)0x00300000)
#define RCC_PLLMul_15 ((u32)0x00340000)
#define RCC_PLLMul_16 ((u32)0x00380000)
#define IS_RCC_PLL_MUL(MUL) (((MUL) == RCC_PLLMul_2) || ((MUL) == RCC_PLLMul_3) ||
((MUL) == RCC_PLLMul_4) || ((MUL) == RCC_PLLMul_5) ||
((MUL) == RCC_PLLMul_6) || ((MUL) == RCC_PLLMul_7) ||
((MUL) == RCC_PLLMul_8) || ((MUL) == RCC_PLLMul_9) ||
((MUL) == RCC_PLLMul_10) || ((MUL) == RCC_PLLMul_11) ||
((MUL) == RCC_PLLMul_12) || ((MUL) == RCC_PLLMul_13) ||
((MUL) == RCC_PLLMul_14) || ((MUL) == RCC_PLLMul_15) ||
((MUL) == RCC_PLLMul_16))
/* System clock source */
/********RCC_CFGR时钟配置寄存器***********
第1:0位:SW[1:0] 系统时钟切换
00:HSI作为系统时钟
01:HSE作为系统时钟
10:PLL输出作为系统时钟
***************END**********************/
#define RCC_SYSCLKSource_HSI ((u32)0x00000000)
#define RCC_SYSCLKSource_HSE ((u32)0x00000001)
#define RCC_SYSCLKSource_PLLCLK ((u32)0x00000002)
#