基本数据类型的封装
#define __IO volatile /*!< Defines 'read / write' permissions */
/* exact-width signed integer types */
typedef signed char int8_t;
typedef signed short int int16_t;
typedef signed int int32_t;
typedef signed __INT64 int64_t;
/* exact-width unsigned integer types */
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __INT64 uint64_t;
/* Logical defines and NULL */
#ifdef FALSE
#undef FALSE
#endif
#define FALSE (1 == 0)
#ifdef TRUE
#undef TRUE
#endif
#define TRUE (1 == 1)
#ifndef NULL
#define NULL (void *) 0
#endif
GPIO 结构体定义
/**
* @brief General Purpose I/O
*/
typedef struct
{
__IO uint32_t MODER; /*!< GPIO port mode register, Address offset: 0x00 */
__IO uint32_t OTYPER; /*!< GPIO port output type register, Address offset: 0x04 */
__IO uint32_t OSPEEDR; /*!< GPIO port output speed register, Address offset: 0x08 */
__IO uint32_t PUPDR; /*!< GPIO port pull-up/pull-down register, Address offset: 0x0C */
__IO uint32_t IDR; /*!< GPIO port input data register, Address offset: 0x10 */
__IO uint32_t ODR; /*!< GPIO port output data register, Address offset: 0x14 */
__IO uint32_t BSRR; /*!< GPIO port bit set/reset, Address offset: 0x18 */
__IO uint32_t LCKR; /*!< GPIO port configuration lock register, Address offset: 0x1C */
__IO uint32_t AFR[2]; /*!< GPIO alternate function registers, Address offset: 0x20-0x24 */
} GPIO_TypeDef;
GPIO 引脚定义,强转为指针
/** @addtogroup Peripheral_declaration
* @{
*/
#define GPIOA ((GPIO_TypeDef *) GPIOA_BASE)
#define GPIOB ((GPIO_TypeDef *) GPIOB_BASE)
#define GPIOC ((GPIO_TypeDef *) GPIOC_BASE)
#define GPIOD ((GPIO_TypeDef *) GPIOD_BASE)
#define GPIOE ((GPIO_TypeDef *) GPIOE_BASE)
#define GPIOF ((GPIO_TypeDef *) GPIOF_BASE)
基本方法:(基地址 + 偏移地址)
/*!< D3_AHB1PERIPH peripherals */
#define GPIOA_BASE (D3_AHB1PERIPH_BASE + 0x0000UL)
#define GPIOB_BASE (D3_AHB1PERIPH_BASE + 0x0400UL)
#define GPIOC_BASE (D3_AHB1PERIPH_BASE + 0x0800UL)
#define GPIOD_BASE (D3_AHB1PERIPH_BASE + 0x0C00UL)
#define GPIOE_BASE (D3_AHB1PERIPH_BASE + 0x1000UL)
#define GPIOF_BASE (D3_AHB1PERIPH_BASE + 0x1400UL)
/*!< Peripheral memory map */
#define D3_AHB1PERIPH_BASE (PERIPH_BASE + 0x18020000UL)
/** @addtogroup Peripheral_memory_map
* @{
*/
#define PERIPH_BASE (0x40000000UL) /*!< Base address of : AHB/APB Peripherals