匿名
未登录
登录
百问网嵌入式Linux wiki
搜索
查看“CAN overview”的源代码
来自百问网嵌入式Linux wiki
名字空间
页面
讨论
更多
更多
页面选项
Read
查看源代码
历史
←
CAN overview
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
This article gives information about the Linux<sup>®</sup> Controller Area Network (CAN) framework. It explains how to activate the CAN interface and, based on examples, how to use it. == Framework purpose == The '''Controller Area Network''' (CAN) is a multi-master serial bus standard connecting at least two nodes. It is a message-based protocol originally designed for in-vehicle communication and which main benefits are a significant reduction of wiring and the prevention of message collision. For better real-time performance, CAN with Flexible Data-Rate (CAN FD)<ref>[https://www.can-cia.org/can-knowledge/can/can-fd/ CAN FD - The basic idea], from the CAN in Automation group (CiA)</ref> is used as an extension to the classic CAN protocol<ref>[https://www.can-cia.org/can-knowledge/can/can-implementations/ CAN protocol implementations], from the CAN in Automation group (CiA)</ref>. It allows data rates higher than 1 MBit/s and payloads longer than 8 bytes per frame (up to 64 data bytes). '''SocketCAN''' <ref name=SocketCAN>{{CodeSource | Linux kernel | Documentation/networking/can.rst | Kernel SocketCAN documentation}}, Linux Foundation</ref> is a uniform CAN Framework for the Linux kernel. It implements a new protocol family called '''PF_CAN'''<ref name=PF_CAN>{{CodeSource | Linux kernel | net/can/af_can.c | net/can/af_can.c}}, Protocol family CAN core module</ref> and allows applications to receive and transmit CAN messages via Socket APIs with CAN specific socket options. You can find many applications of CAN in the automotive industry. In vehicles, it allows electronic control units and devices to communicate with each other in applications without a host computer. For example, a high speed CAN bus is dedicated to security devices such as emergency brake system or airbags. Another low speed CAN bus is dedicated to comfort devices such as interiror lighting or seat control. This article describes the main components and APIs of the CAN Framework and gives examples of CAN usage. ==System overview== [[File:CAN overview V1.0.png|thumb|link=|center|766px|alt=Alternate text|CAN Overview]] ===Component description=== ''From user space to hardware'' *'''Application''' (User space) Application to read/write data on the [[CAN overview#API description | SocketCAN interface]] for communication with external devices connected on the CAN network (such as can-utils). *'''CAN tools''' (User space) Set of utilities for configuring and enabling SocketCAN interface (such as iproute2). *'''SocketCAN''' (Kernel space) Socket interface with specific CAN options which builds upon the Linux network layer. *'''Linux Socket Layer and CAN Protocols (PF_CAN)''' (Kernel space) The protocol family, PF_CAN<ref name=PF_CAN/>, provides an API for transport protocol modules to register and the structures to enable different CAN protocols on the bus. *'''Linux Networking Core''' (Kernel space) Kernel network layer that adapts the message to the transport protocol in use. The network subsystem of the Linux kernel is designed to be completely protocol-independent. *'''M_CAN Driver''' (Kernel space) Driver implemented as a network interface for Bosch M_CAN controller<ref name=M_CAN>{{CodeSource | Linux kernel | drivers/net/can/m_can}}, Driver for Bosch M_CAN controller</ref>. *'''CAN''' (Hardware) This is the CAN Core IP. *'''CAN Transceiver''' (Hardware) Interface between the CAN protocol controller and the physical wires of the CAN bus lines. ===API description=== The SocketCAN interface API description can be found in kernel documentation <ref name=SocketCAN/>. ==Configuration == ===Kernel configuration=== Activate the CAN driver in kernel configuration with Linux [[Menuconfig or how to configure kernel | Menuconfig ]] tool. For compiling M_CAN driver, select "Bosch M_CAN devices": <pre> [*] Networking support ---> <*> CAN bus subsystem support ---> CAN Device Drivers ---> <*> Bosch M_CAN devices </pre> M_CAN driver is activated by default in ST deliveries. ===Device tree configuration=== CAN generic DT bindings: * The M_CAN device tree bindings<ref>{{CodeSource | Linux kernel | Documentation/devicetree/bindings/net/can/m_can.txt | Documentation/devicetree/bindings/net/can/m_can.txt}} M_CAN device tree bindings</ref> describe all the required and optional properties. Detailed DT configuration for STM32 internal peripherals: * [[FDCAN device tree configuration]] == How to use the framework== The CAN device must be configured via netlink interface. The following articles give user space examples of how to set up a SockeCAN interface (and configure settings like bit-timing parameters) and how to send/receive data on the CAN bus. === How to set up a SocketCAN interface === [[How to set up a SocketCAN interface]] === How to send/receive CAN data === [[How to send or receive CAN data]] ==How to trace and debug the framework== === How to trace === CAN Framework, specifically M_CAN driver, print out info and error messages. You can display them with dmesg command: {{Board$}} '''dmesg | grep m_can''' [ 1.327824] m_can 4400e000.can: m_can device registered (irq=30, version=32) [ 25.560759] m_can 4400e000.can can0: bitrate error 0.3% [ 25.564630] m_can 4400e000.can can0: bitrate error 1.6% === How to monitor CAN bus === You can use the CAN FD adapter '''PCAN-USB Pro FD'''<ref>[http://www.peak-system.com/PCAN-USB-Pro-FD.366.0.html?&L=1 PCAN-USB Pro FD description], by PEAK System</ref> to connect a computer to the CAN network via USB. The PCAN-View software provided with the tool is a monitoring program that allows to supervise the data flow on the CAN network and to detect frame errors. ==Source code location== The source files are located inside the Linux kernel. *'''PF_CAN''': af_can.c<ref name=PF_CAN/> *'''M_CAN driver''': m_can.c<ref name=M_CAN/> ==To go further== CAN bit timing calculation plays an important role in ensuring performance of CAN network. To avoid transmission errors, the bit timing must be configured properly. For more information about CAN bit timing: * ''Computation of CAN Bit Timing Parameters Simplified''<ref>[https://www.can-cia.org/fileadmin/resources/documents/proceedings/2012_taralkar.pdf Computation of CAN Bit Timing Parameters Simplified], from the CAN in Automation group (CiA)</ref>, from the CAN in Automation group (CiA) * ''The Configuration of the CAN Bit Timing''<ref>[https://www.mikrocontroller.net/attachment/114193/BOSCH_The_config_of_CAN_Bit_Timing_L-1.pdf The Configuration of the CAN Bit Timing], from Bosch documentation</ref>, from Bosch documentation ==References== <references />
该页面使用的模板:
模板:Board$
(
查看源代码
)
模板:CodeSource
(
查看源代码
)
返回至
CAN overview
。
导航
导航
WIKI首页
官方店铺
资料下载
交流社区
所有页面
所有产品
MPU-Linux开发板
MCU-单片机开发板
Linux开发系列视频
单片机开发系列视频
所有模块配件
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志