简略的总结了一下stm32 寄存器读写代码风格,以备后用:
依据memory mapping 直接写寄存器代码风格:
#define GPIOA_BASE1 (uint32_t)0x40010800#define GPIOA_CRH ((uint32_t*)(GPIOA_BASE1+0x04))
转换为指针之后,直接读写:
*GPIOA_CRH=0x000004B0;//A端口//复用推挽输出
结构体指针处理接连多个寄存器读写设置:
#define Usart1_BASE 0x40013800typedef struct{__IO uint32_t SR;__IO uint32_t DR;__IO uint32_t BRR;__IO uint32_t CR1;__IO uint32_t CR2;__IO uint32_t CR3;__IO uint32_t GTPR;}Usart1_typedef;#define Usart1 ((Usart1_typedef*)Usart1_BASE)
Usart1->CR1=0x0000000C;