在使用RT-Thread 3.1.x 时, warning: #1296-D: extended constant initialiser used处理

本文探讨了在RT-Thread3.1.x中配置GPIO驱动时遇到的warning:#1296-D告警问题及解决方案。通过对代码进行调整,解决了Keil编译器产生的警告,并分析了后续出现的问题。

最近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编译后告警消失。

但是后来验证发现,改后指示灯端口未能正确初始化,指示灯点不亮。还得改回来,问题正在进一步研究中。

 

 

 

 

 

 

 

 

 

 

 

 

*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin' Rebuild target 'Main' compiling cfg_value.c... compiling conn.c... ..\conn.c(20): warning: #177-D: variable "can_box" was declared but never referenced CAN_FIFOMailBox_TypeDef *can_box; ..\conn.c: 1 warning, 0 errors compiling IO.c... compiling stm32f10x_it.c... compiling updata.c... ..\updata.c(78): warning: #177-D: variable "add" was declared but never referenced uint32_t add,file_flag; ..\updata.c(78): warning: #177-D: variable "file_flag" was declared but never referenced uint32_t add,file_flag; ..\updata.c: 2 warnings, 0 errors compiling main.c... ..\main.c(87): warning: #1296-D: extended constant initialiser used {0,(u32)motor_step_cmd_demo}, ..\main.c(88): warning: #1296-D: extended constant initialiser used {0,(u32)cfg_write_buf}, ..\main.c(94): warning: #177-D: variable "status" was declared but never referenced static u8 status=0; ..\main.c: 3 warnings, 0 errors compiling HardWare.c... ..\HardWare.c(162): warning: #188-D: enumerated type mixed with another type GPIO_WriteBit( TEP_CFG2_GPIO, TEP_CFG2_PIN,val&1); ..\HardWare.c(163): warning: #188-D: enumerated type mixed with another type GPIO_WriteBit( TEP_CFG3_GPIO, TEP_CFG3_PIN,(val>>1)&1); ..\HardWare.c(164): warning: #188-D: enumerated type mixed with another type GPIO_WriteBit( TEP_CFG4_GPIO, TEP_CFG4_PIN,(val>>1)&1); ..\HardWare.c(501): warning: #111-D: statement is unreachable if ((CAN1->TSR&CAN_TSR_TME2) != CAN_TSR_TME2) ..\HardWare.c: 4 warnings, 0 errors compiling stm32f10x_crc.c... compiling stm32f10x_flash.c... compiling stm32f10x_rcc.c... compiling stm32f10x_gpio.c... compiling motor.c... ..\motor.c(487): warning: #177-D: variable "i" was declared but never referenced uint32_t i,time_run; ..\motor.c(488): warning: #177-D: variable "ptr16" was declared but never referenced uint16_t *ptr16,ad_val; //最大4096 *10 不会超过16位 ..\motor.c(855): warning: #177-D: variable "i" was declared but never referenced uint32_t i,time_run; ..\motor.c(1493): error: #1182: a declaration cannot have a label long pulses; ..\motor.c(1494): error: #268: declaration may not appear after executable statement in block uint32_t calc_temp ; ..\motor.c(1495): error: #268: declaration may not appear after executable statement in block uint32_t cur_mm10 ; ..\motor.c: 3 warnings, 3 errors compiling stm32f10x_can.c... compiling misc.c... compiling stm32f10x_dma.c... compiling stm32f10x_usart.c... compiling stm32f10x_spi.c... compiling stm32f10x_exti.c... compiling stm32f10x_dbgmcu.c... compiling stm32f10x_adc.c... compiling stm32f10x_tim.c... compiling stm32f10x_iwdg.c... compiling system_stm32f10x.c... assembling startup_stm32f10x_md.s... compiling core_cm3.c... ".\obj\ir_12.axf" - 3 Error(s), 13 Warning(s). Target not created. Build Time Elapsed: 00:00:20 解读一下报错信息
最新发布
09-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

aping_cs_dn

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值