自己建STM32库的错误提示

//外设 p
#define PERIPH_BASE ((unsigned int)0X40000000)

// #define APB2PERIPH_BASE (PERIPH_BASE+0X10000) 这样写就是错的

#define APB2PERIPH_BASE PERIPH_BASE+0X10000
#define APBPERIPH_BASE PERIPH_BASE+0X20000

#define RCC_BASE (APBPERIPH_BASE+0X1000)
#define GPIOB_BASE (APB2PERIPH_BASE+0X0C00)

#define RCC_APB2EN *(unsigned int*)(RCC_BASE+0X18) //第一个*是取地址 地址:(unsigned int*)(RCC_BASE+0X18)

#define GPIOB_CRL *(unsigned int*)(GPIOB_BASE+0X00) //
#define GPIOB_CRH *(unsigned int*)(GPIOB_BASE+0X04)
#define GPIOB_IDR *(unsigned int*)(GPIOB_BASE+0X08)
#define GPIOB_ODR *(unsigned int*)(GPIOB_BASE+0X0C) //
#define GPIOB_BSRR *(unsigned int*)(GPIOB_BASE+0X10)
#define GPIOB_BRR *(unsigned int*)(GPIOB_BASE+0X14) //
#define GPIOB_LCKR *(unsigned int*)(GPIOB_BASE+0X18)

 #define APB2PERIPH_BASE (PERIPH_BASE+0X10000) 这样写编译器GPIOB_CRL |= (1<<4*5); 会有错

 

假如存储路径有中文,结构体定义后,在程序中调用会出现->不能自动加载结构体成员

 

//不加括号是错误的 #define        RCC_BASE                    APBPERIPH_BASE+0X1000  
#define        RCC_BASE                    (APBPERIPH_BASE+0X1000)
typedef unsigned int             uint32_t;
typedef unsigned short        uint16_t;

typedef struct
{
        uint32_t CRL;
        uint32_t CRH;
        uint32_t IDR;
        uint32_t ODR;
        uint32_t BSRR;
        uint32_t BRR;
        uint32_t LCKR;

}GPIO_TypeDef;

#define GPIOB        ((GPIO_TypeDef*)GPIOB_BASE)
//GPIOB_BASE的基地址是0x40010C00
//#define GPIOB        ((GPIO_TypeDef*)0x40010C00)是对的,检测出错的地方

 

 

posted on 2020-04-22 14:52  苏邮临  阅读(374)  评论(0)    收藏  举报

导航