STM32F10x.h头文件代码
时间: 2023-11-13 17:05:03 浏览: 366
由于STM32F10x.h头文件比较大,这里只展示其中部分主要内容的代码。完整的STM32F10x.h头文件可以在STMicroelectronics官网上下载。
```c
#ifndef __STM32F10x_H
#define __STM32F10x_H
#include "core_cm3.h" // CMSIS头文件,包含Cortex-M3内核相关的宏和函数
// 定义STM32F10x系列微控制器的型号,例如STM32F103xB
#if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) && !defined (STM32F10X_MD) && !defined (STM32F10X_MD_VL) && \
!defined (STM32F10X_HD) && !defined (STM32F10X_HD_VL) && !defined (STM32F10X_XL) && !defined (STM32F10X_CL)
#define STM32F10X_LD
#endif
// 定义STM32F10x系列微控制器的系统时钟频率
#if !defined HSI_VALUE
#define HSI_VALUE ((uint32_t)8000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
#if !defined HSE_VALUE
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#define SYSCLK_FREQ_HSI HSI_VALUE /*!< System clock frequency with HSI as reference clock */
#define SYSCLK_FREQ_72MHz 72000000UL /*!< System clock frequency with PLL enabled and HSE as reference clock */
// 定义一些常用的类型和宏
typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState;
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus, BitStatus;
typedef enum {ERROR = 0, SUCCESS = !ERROR} ErrorStatus;
#define IS_FUNCTIONAL_STATE(STATE) (((STATE) == DISABLE) || ((STATE) == ENABLE))
#define IS_FLAG_STATUS(STATUS) (((STATUS) == RESET) || ((STATUS) == SET))
#define IS_IT_STATUS(STATUS) (((STATUS) == RESET) || ((STATUS) == SET))
#define IS_BIT_STATUS(STATUS) (((STATUS) == RESET) || ((STATUS) == SET))
#define IS_ERROR_STATUS(STATUS) (((STATUS) == ERROR) || ((STATUS) == SUCCESS))
// 定义IO口类型
typedef struct
{
__IO uint32_t CRL;
__IO uint32_t CRH;
__IO uint32_t IDR;
__IO uint32_t ODR;
__IO uint32_t BSRR;
__IO uint32_t BRR;
__IO uint32_t LCKR;
} GPIO_TypeDef;
// 定义外设寄存器类型
typedef struct
{
__IO uint32_t CR1;
__IO uint32_t CR2;
__IO uint32_t SR;
__IO uint32_t DR;
__IO uint32_t CRCPR;
__IO uint32_t RXCRCR;
__IO uint32_t TXCRCR;
__IO uint32_t I2SCFGR;
} SPI_TypeDef;
// 定义一些常用的函数
void NVIC_EnableIRQ(IRQn_Type IRQn);
void GPIO_Init(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, uint32_t GPIO_Mode);
#endif /* __STM32F10x_H */
```
阅读全文