匿名
未登录
登录
百问网嵌入式Linux wiki
搜索
查看“How to set up a SocketCAN interface”的源代码
来自百问网嵌入式Linux wiki
名字空间
页面
讨论
更多
更多
页面选项
Read
查看源代码
历史
←
如何设置SocketCAN接口
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
{{DISPLAYTITLE:如何设置SocketCAN接口}} =如何配置 SocketCAN 接口= ==目的== : 本文介绍如何使用 iproute2 [1 ]工具套件配置 SocketCAN 接口。 : iproute2 是一组用于 Linux® 网络的命令行实用程序,已集成在 STM32 微处理器的 SDK 中。 ==配置 SocketCAN 接口== : 可用的 CAN 设备在 /sys/class/net/ 中列出: <syntaxhighlight lang="bash"> Board $> ls /sys/class/net can0 eth0 /* can0 interface is available but not necessarily active */ </syntaxhighlight> : 还可以显示所有可用的网络接口以找出可用的 CAN 设备: <syntaxhighlight lang="bash"> Board $> ifconfig -a can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 NOARP MTU:16 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:10 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:30 eth0 Link encap:Ethernet HWaddr 00:80:E1:42:45:EC UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) Interrupt:54 Base address:0x6000 </syntaxhighlight> : 使用 ip link 命令行配置可用的 SocketCAN 接口,如下所示: <syntaxhighlight lang="bash"> Board $> ip link set can0 type can bitrate 1000000 dbitrate 2000000 fd on [ 78.700698] m_can 4400e000.can can0: bitrate error 0.3% [ 78.704568] m_can 4400e000.can can0: bitrate error 1.6% </syntaxhighlight> : 要列出 CAN 用户可配置的选项,请使用以下命令: <syntaxhighlight lang="bash"> Board $> ip link set can0 type can help Usage: ip link set DEVICE type can [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1 phase-seg2 PHASE-SEG2 [ sjw SJW ] ] [ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | [ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1 dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ] [ loopback { on | off } ] [ listen-only { on | off } ] [ triple-sampling { on | off } ] [ one-shot { on | off } ] [ berr-reporting { on | off } ] [ fd { on | off } ] [ fd-non-iso { on | off } ] [ presume-ack { on | off } ] [ restart-ms TIME-MS ] [ restart ] Where: BITRATE := { 1..1000000 } SAMPLE-POINT := { 0.000..0.999 } TQ := { NUMBER } PROP-SEG := { 1..8 } PHASE-SEG1 := { 1..8 } PHASE-SEG2 := { 1..8 } SJW := { 1..4 } RESTART-MS := { 0 | NUMBER } </syntaxhighlight> ==打印 SocketCAN 信息== : 要获取 SocketCAN 链接的详细状态,请使用以下命令: <syntaxhighlight lang="bash"> Board $> ip -details link show can0 2: can0: <NOARP,ECHO> mtu 72 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10 link/can promiscuity 0 can <FD> state STOPPED (berr-counter tx 0 rx 0) restart-ms 0 bitrate 996078 sample-point 0.745 tq 19 prop-seg 18 phase-seg1 19 phase-seg2 13 sjw 1 m_can: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..512 brp-inc 1 dbitrate 2032000 dsample-point 0.720 dtq 19 dprop-seg 8 dphase-seg1 9 dphase-seg2 7 dsjw 1 m_can: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..32 dbrp-inc 1 clock 50800000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 </syntaxhighlight> ==启用/禁用 SocketCAN 接口== : 然后通过打开 SocketCAN 接口来启用连接: <syntaxhighlight lang="bash"> Board $> ip link set can0 up </syntaxhighlight> : 可以通过下面的命令打印网络链接状态信息来检查接口是否已启动: <syntaxhighlight lang="bash"> Board $> ip -details link show can0 2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10 link/can promiscuity 0 can <FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 bitrate 996078 sample-point 0.745 ... </syntaxhighlight> : 可以通过关闭 SocketCAN 接口来禁用连接。当需要重新配置 SocketCAN 接口时,这个命令很有用: <syntaxhighlight lang="bash"> Board $> ip link set can0 down </syntaxhighlight> ==回环测试模式== : 可以在内部环回测试模式下配置 SocketCAN。在这种情况下,FDCAN 将其自身的已发送消息视为已接收消息。此模式可用于硬件自检: <syntaxhighlight lang="bash"> Board $> ip link set can0 type can bitrate 1000000 dbitrate 2000000 fd on loopback on </syntaxhighlight> : 可以通过下面的命令打印网络链接状态信息来检查环回选项是否打开: <syntaxhighlight lang="bash"> Board $> ip -details link show can0 2: can0: <NOARP,ECHO> mtu 72 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10 link/can promiscuity 0 can <LOOPBACK,FD> state STOPPED (berr-counter tx 0 rx 0) restart-ms 0 bitrate 996078 sample-point 0.745 ... </syntaxhighlight> ==SocketCAN 接口设置示例== : 可以在同一命令行中配置和启用 SocketCAN 接口: <syntaxhighlight lang="bash"> Board $> ip link set can0 up type can bitrate 1000000 dbitrate 2000000 fd on [ 78.700698] m_can 4400e000.can can0: bitrate error 0.3% [ 78.704568] m_can 4400e000.can can0: bitrate error 1.6% [ 78.710140] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready </syntaxhighlight> ==参考== : 1. [https://wiki.linuxfoundation.org/networking/iproute2 IPROUTE2 信息],由 Linux Foundation 提供 [[Category:Linux_Operating_System]] [[Category:Networking]] [[Category:Netdev]] [[Category:CAN]]
返回至
如何设置SocketCAN接口
。
导航
导航
WIKI首页
官方店铺
资料下载
交流社区
所有页面
所有产品
MPU-Linux开发板
MCU-单片机开发板
Linux开发系列视频
单片机开发系列视频
所有模块配件
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志