1 宏定义如下:
#define nGPIO_MODE_HSET(m,p,n) SYS->GP##p##_MFPH =(SYS->GP##p##_MFPH & (~(1<<(4*(n-8))))); P##p##->MODE = (P##p##->MODE &(~( 3<<(n<<1))) | ( m<<(n<<1)))
2 函数调用
nGPIO_MODE_HSET(OUT_GPIO, D, 15);
3编译结果
Source\output\output.c(150): warning: #61-D: integer operation result is out of range
GPIO_MODE_HSET(OUT_GPIO, D, 15);//PD.15设置为输出,辅助位置1
4 查明原因:
编译器默认signed int即32位有符号整数类型,而1<<31实际为0x80000000,这样就有可能改写了符号位(最高位)。
5 修改宏定义
#define nGPIO_MODE_HSET(m,p,n) SYS->GP##p##_MFPH =(SYS->GP##p##_MFPH & (~((uint32)1<<(4*(n-8))))); P##p##->MODE = (P##p##->MODE &(~( (uint32)3<<(n<<1))) | ( m<<(n<<1)))
编译警告消失