最近RT-Thread 3.1.x 时,在配置gpio驱动程序时,遇到warning: #1296-D: extended constant initialiser used告警,通过搜索一直没有找到答案,从官网提供的解决方法得到一点灵感:
Why do I see "Warning: #1296-D: extended constant initialiser used"?
Applies to: RealView Development Suite (RVDS)
Answer
When compiling C code containing statements like this:
int x;
int y = (int) &x;
where x
and y
are static objects (global variables or static local variables), the compiler will report:
Warning: #1296-D: extended constant initialiser used
解决方法:
int x;
int* y = &x;
so that y
is now a pointer to x
.
RT-Thread的STM32目录下开发板支持包下的drv_gpio.h有定义:
GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( ((rt_base_t)__STM32_PORT(PORTx) - (rt_base_t)GPIOA)/(0x0400UL) )) + PIN)
我再drv_led.c驱动文件中引用
#ifdef BSP_USING_LED1_PIN
/*LED1_PIN --> PA15 */
#define LED1_PIN GET_PINxy(A,15)
#define DRV_LED1_CONFIG \
{ \
.led_name = "led1", \
.led_pin = LED1_PIN, \
}
#endif
Keil编译时产生告警:
warning: #1296-D: extended constant initialiser used
现将其修改上面定义修改如下:
#define GET_PIN(PORTx,PIN) (rt_base_t)((16 * ( (rt_base_t)(__STM32_PORT(PORTx) - GPIOA)/(0x0400UL) )) + PIN)
Keil编译后告警消失。
但是后来验证发现,改后指示灯端口未能正确初始化,指示灯点不亮。还得改回来,问题正在进一步研究中。