Difference between revisions of "CAN bus Linux driver"

From ArmadeusWiki
Jump to: navigation, search
Line 29: Line 29:
 
<pre class="apf">
 
<pre class="apf">
 
modprobe can
 
modprobe can
modprobe can-dev # if > armadeus-3.4
+
modprobe can-dev
modprobe candev  # if <= armadeus-3.4
+
 
modprobe can-raw  
 
modprobe can-raw  
 
modprobe mcp251x
 
modprobe mcp251x
 
</pre>
 
</pre>
* Set the bitrate before all operations (if > armadeus-3.4 only)
+
* Set the bitrate before all operations
 
Example:
 
Example:
 
Set the bitrate of the can interface can0 on 125kbps
 
Set the bitrate of the can interface can0 on 125kbps
Line 40: Line 39:
 
ip link set can0 up type can bitrate 125000
 
ip link set can0 up type can bitrate 125000
 
</pre>
 
</pre>
If your version of armadeus is down or equal to the 3.4 version, the baudrate is fixed to 250kbps. To change this value, please upgrade your armadeus version.
 
  
 
==Quick test==
 
==Quick test==

Revision as of 18:50, 13 April 2011

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.

Warning Warning: Please ensure that you use the trunk version of armadeus (kernel linux-2.6.38.1 is required) before effectuate the operations described on 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> Microchip 251x series SPI CAN Controller
 $ 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

Quick test

Once the driver installed, 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
        [*]     install test tools
$ make

then, reflash your rootfs.

Links