微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > stm32f10x.h文件分析理解

stm32f10x.h文件分析理解

时间:11-10 来源:互联网 点击:

对上面定义的结构体的成员,即寄存器映射到相应的地址上,以下包括一个是地址映射,一个是寄存器声明。

/** @addtogroup Peripheral_memory_map* @{*/#define FLASH_BASE            ((uint32_t)0x08000000) /*!< FLASH base address in the alias region */#define SRAM_BASE             ((uint32_t)0x20000000) /*!< SRAM base address in the alias region */#define PERIPH_BASE           ((uint32_t)0x40000000) /*!< Peripheral base address in the alias region */#define SRAM_BB_BASE          ((uint32_t)0x22000000) /*!< SRAM base address in the bit-band region */#define PERIPH_BB_BASE        ((uint32_t)0x42000000) /*!< Peripheral base address in the bit-band region */#define FSMC_R_BASE           ((uint32_t)0xA0000000) /*!< FSMC registers base address *//*!< Peripheral memory map */#define APB1PERIPH_BASE       PERIPH_BASE#define APB2PERIPH_BASE       (PERIPH_BASE + 0x10000)#define AHBPERIPH_BASE        (PERIPH_BASE + 0x20000)#define TIM2_BASE             (APB1PERIPH_BASE + 0x0000)#define TIM3_BASE             (APB1PERIPH_BASE + 0x0400)....../** @addtogroup Peripheral_declaration* @{*/  #define TIM2                ((TIM_TypeDef *) TIM2_BASE)#define TIM3                ((TIM_TypeDef *) TIM3_BASE)#define TIM4                ((TIM_TypeDef *) TIM4_BASE)#define TIM5                ((TIM_TypeDef *) TIM5_BASE)#define TIM6                ((TIM_TypeDef *) TIM6_BASE)......

一开头讲过,如果定义使用外设驱动,则包含 stm32f10x_conf.h用来配置所使用外设的库函数

#ifdef USE_STDPERIPH_DRIVER#include "stm32f10x_conf.h"#endif

定义一些宏的操作,下面是位操作。

/** @addtogroup Exported_macro* @{*/#define SET_BIT(REG, BIT)     ((REG) |= (BIT))#define CLEAR_BIT(REG, BIT)   ((REG) &= ~(BIT))#define READ_BIT(REG, BIT)    ((REG) & (BIT))#define CLEAR_REG(REG)        ((REG) = (0x0))#define WRITE_REG(REG, VAL)   ((REG) = (VAL))#define READ_REG(REG)         ((REG))#define MODIFY_REG(REG, CLEARMASK, SETMASK)  WRITE_REG((REG), (((READ_REG(REG)) & (~(CLEARMASK))) | (SETMASK)))

#ifdef __cplusplus}#endif#endif /* __STM32F10x_H */

上面的代码源自 ST3.5版本库的 stm32f10x.h 文件。综合以上,可以看出 stm32f10x.h 用于定义了器件、中断线、数据类型、结构体封装的寄存器、寄存器地址映射、寄存器位操作以及防C++编译的条件编译。

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top