Difference between revisions of "CAN bus Linux driver"
m |
|||
Line 2: | Line 2: | ||
SocketCAN is based on the Linux socket. Further details can be found on the links at the bottom of this page. | SocketCAN is based on the Linux socket. Further details can be found on the links at the bottom of this page. | ||
− | {{Warning| Please ensure that you use the trunk version of armadeus | + | {{Warning| Please ensure that you use the trunk version of armadeus (kernel version >= linux-2.6.38 is required) before trying the instructions described on this page!}} |
==Driver installation== | ==Driver installation== | ||
− | |||
− | |||
− | |||
− | |||
<pre class="host"> | <pre class="host"> | ||
$ make linux26-menuconfig | $ make linux26-menuconfig | ||
Line 112: | Line 108: | ||
==Userspace tools== | ==Userspace tools== | ||
− | Several tools are provided by socketCAN: | + | *Several tools are provided by socketCAN: |
− | *'''candump''': dump traffic on a CAN network | + | **'''candump''': dump traffic on a CAN network |
− | + | **'''cansend''': simple command line tool to send CAN-frames via CAN_RAW sockets | |
− | + | **'''cangen''': CAN frames generator for testing purpose | |
− | + | **'''canplayer''': send CAN frames from a file to a CAN interface | |
− | + | ||
− | *'''cansend''': simple command line tool to send CAN-frames via CAN_RAW sockets | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | *'''cangen''': CAN frames generator for testing purpose | + | |
− | *'''canplayer''': send CAN frames from a file to a CAN interface | + | |
− | These tools can be compiled and installed on the target by means of the Buildroot menuconfig: | + | *These tools can be compiled and installed on the target by means of the Buildroot menuconfig: |
<pre class="host"> | <pre class="host"> | ||
$ make menuconfig | $ make menuconfig | ||
Line 151: | Line 133: | ||
* http://ww1.microchip.com/downloads/en/DeviceDoc/21801e.pdf (MCP2515 datasheet) | * http://ww1.microchip.com/downloads/en/DeviceDoc/21801e.pdf (MCP2515 datasheet) | ||
* http://www.kvaser.com/can/protocol/index.htm (CAN introduction) | * http://www.kvaser.com/can/protocol/index.htm (CAN introduction) | ||
− | |||
[[Category:Linux drivers]] | [[Category:Linux drivers]] | ||
[[Category:CAN bus]] | [[Category:CAN bus]] |
Revision as of 14:52, 29 November 2012
The current CAN bus driver uses SocketCAN API which is now the official CAN API for Linux. SocketCAN is based on the Linux socket. Further details can be found on the links at the bottom of this page.
Driver installation
$ make linux26-menuconfig
Networking support ---> <M> CAN bus subsystem support ---> --- CAN bus subsystem support <M> Raw CAN Protocol (raw access with CAN-ID filtering) <M> Broadcast Manager CAN Protocol (with content filtering) CAN Device Drivers ---> <M> Virtual Local CAN Interface (vcan) <M> Platform CAN drivers with Netlink support [*] CAN bit-timing calculation <M> Microchip 251x series SPI CAN Controller
$ make linux26 $ make
- Reflash kernel and rootfs
Usage
- Load all the needed drivers:
modprobe can modprobe can-dev modprobe can-raw modprobe mcp251x
- Set the bitrate before all operations
Example: Set the bitrate of the can interface can0 on 125kbps
# ip link set can0 up type can bitrate 125000
If the following error occurs when you do the last instruction :
ip: either "dev" is duplicate, or "type" is garbage
check that this command:
# which ip
return this message:
/sbin/ip
and not this one :
/bin/ip
If the binary is installed in /bin instead of /sbin, the executable file is a link to busybox and the command to set the bitrate doesn't work on busybox, so try the following instructions:
$ make busybox-clean $ make busybox-dirclean $ make menuconfig
Package Selection for the target ---> Networking applications ---> [*] iproute2
$ make
Then, reflash your rootfs.
Quick test
Once the driver installed and the bitrate is set, the CAN interface has to be started like a standard net interface
# ifconfig can0 up
and can be stopped like that:
# ifconfig can0 down
The socketCAN version can be retrieved like that:
# cat /proc/net/can/version
The socketCAN statistics can be retrieved like that:
# cat /proc/net/can/stats
Userspace tools
- Several tools are provided by socketCAN:
- candump: dump traffic on a CAN network
- cansend: simple command line tool to send CAN-frames via CAN_RAW sockets
- cangen: CAN frames generator for testing purpose
- canplayer: send CAN frames from a file to a CAN interface
- These tools can be compiled and installed on the target by means of the Buildroot menuconfig:
$ make menuconfig
Package Selection for the target ---> Networking ---> [*] Socket CAN
$ make
then, reflash your rootfs.
Links
- https://www.ridgerun.com/developer/wiki/index.php/How_to_configure_and_use_CAN_bus (How to configure and use CAN bus)
- http://developer.berlios.de/projects/socketcan/ (CAN Linux Driver)
- http://ww1.microchip.com/downloads/en/DeviceDoc/21801e.pdf (MCP2515 datasheet)
- http://www.kvaser.com/can/protocol/index.htm (CAN introduction)