嵌入式技术论坛
直播中

贾埃罗

7年用户 1664经验值
私信 关注
[问答]

RT-Thread1.4.1.0添加CAN通讯,编译报错如何解决?

问题1.4.1.0的内核版本,使用官方最新更新的CAN驱动,出现报错。报错内容如下:

../drivers/drv_can.c: In function '_can_config':
../drivers/drv_can.c:152:10: error: 'RT_CAN_MODE_LISTEN' undeclared (first use in this function)
case RT_CAN_MODE_LISTEN:
^
../drivers/drv_can.c:152:10: note: each undeclared identifier is reported only once for each function it appears in
../drivers/drv_can.c:158:10: error: 'RT_CAN_MODE_LOOPBACKANLISTEN' undeclared (first use in this function)
case RT_CAN_MODE_LOOPBACKANLISTEN:
^
../drivers/drv_can.c: In function '_can_control':
../drivers/drv_can.c:336:41: error: 'struct rt_can_filter_item' has no member named 'hdr_bank'
if (filter_cfg->items[i].hdr_bank == -1)
^
../drivers/drv_can.c:353:76: error: 'struct rt_can_filter_item' has no member named 'hdr_bank'
drv_can->FilterConfig.FilterBank = filter_cfg->items[i].hdr_bank;
^
../drivers/drv_can.c:404:82: error: 'struct rt_can_filter_item' has no member named 'rxfifo'
drv_can->FilterConfig.FilterFIFOAssignment = filter_cfg->items[i].rxfifo;/rxfifo = CAN_RX_FIFO0/CAN_RX_FIFO1/
^
../drivers/drv_can.c:414:27: error: 'RT_CAN_MODE_LISTEN' undeclared (first use in this function)
argval != RT_CAN_MODE_LISTEN &&
^
../drivers/drv_can.c:416:27: error: 'RT_CAN_MODE_LOOPBACKANLISTEN' undeclared (first use in this function)
argval != RT_CAN_MODE_LOOPBACKANLISTEN)
^
../drivers/drv_can.c: In function '_can_recvmsg':
../drivers/drv_can.c:615:9: error: 'struct rt_can_msg' has no member named 'rxfifo'
pmsg->rxfifo = fifo;
^
../drivers/drv_can.c:622:13: error: 'struct rt_can_msg' has no member named 'hdr_index'
pmsg->hdr_index = rxheader.FilterMatchIndex;
^
../drivers/drv_can.c:627:12: error: 'struct rt_can_msg' has no member named 'hdr_index'
pmsg->hdr_index = rxheader.FilterMatchIndex;
^
make: *** [drivers/subdir.mk:72: drivers/drv_can.o] Error 1
make: *** Waiting for unfinished jobs....
../drivers/drv_common.c:16:13: warning: 'reboot' defined but not used [-Wunused-function]

回帖(2)

五斤麻辣油

2023-9-3 14:37:00
用最新的can.h
举报

王浩

2023-9-26 10:28:43
in this function)case RT_CAN_MODE_LOOPBACKANLISTEN:^../drivers/drv_can.c:158:10: note: each undeclared identifier is reported only once for each function it appears in

解决办法:

1. 检查是否下载了最新的RT-Thread1.4.1.0 CAN驱动

2. 检查该错误信息,关注“undeclared”的提示,在错误的代码中找出对应的变量或宏定义

3. 在项目的配置文件中添加对应的宏定义,或在头文件中加入缺失的头文件

4. 重新编译并检查是否解决问题

示例:

对于上述错误,解决办法为添加RT_CAN_MODE_LISTEN和RT_CAN_MODE_LOOPBACKANLISTEN两个宏定义。

在项目的配置文件中添加如下代码:

#define RT_CAN_MODE_LISTEN 1

#define RT_CAN_MODE_LOOPBACKANLISTEN 2

或在头文件drv_can.c中添加缺少的头文件:

#include "rt_can.h"

#include "rtconfig.h"

然后重新编译,检查问题是否被解决。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分