标准库版本
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO口地址映射
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
直接寄存器操作
#define PAout(n) *((volatile unsigned int*)(((0x40020000-0x40000000+0x14)*8+n)*4+0x42000000))
#define PBout(n) *((volatile unsigned int*)(((0x40020400-0x40000000+0x14)*8+n)*4+0x42000000))
#define PCout(n) *((volatile unsigned int*)(((0x40020800-0x40000000+0x14)*8+n)*4+0x42000000))
#define PDout(n) *((volatile unsigned int*)(((0x40020C00-0x40000000+0x14)*8+n)*4+0x42000000))
#define PEout(n) *((volatile unsigned int*)(((0x40021000-0x40000000+0x14)*8+n)*4+0x42000000))
#define PFout(n) *((volatile unsigned int*)(((0x40021400-0x40000000+0x14)*8+n)*4+0x42000000))
#define PGout(n) *((volatile unsigned int*)(((0x40021800-0x40000000+0x14)*8+n)*4+0x42000000))
#define PAin(n) *((volatile unsigned int*)(((0x40020000-0x40000000+0x10)*8+n)*4+0x42000000))
#define PBin(n) *((volatile unsigned int*)(((0x40020400-0x40000000+0x10)*8+n)*4+0x42000000))
#define PCin(n) *((volatile unsigned int*)(((0x40020800-0x40000000+0x10)*8+n)*4+0x42000000))
#define PDin(n) *((volatile unsigned int*)(((0x40020C00-0x40000000+0x10)*8+n)*4+0x42000000))
#define PEin(n) *((volatile unsigned int*)(((0x40021000-0x40000000+0x10)*8+n)*4+0x42000000))
#define PFin(n) *((volatile unsigned int*)(((0x40021400-0x40000000+0x10)*8+n)*4+0x42000000))
#define PGin(n) *((volatile unsigned int*)(((0x40021800-0x40000000+0x10)*8+n)*4+0x42000000))