Difference between revisions of "CAN bus Linux driver"

From ArmadeusWiki
Jump to: navigation, search
(Userspace tools)
m (Userspace tools)
Line 38: Line 38:
  
 
==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
+
**'''cansend''': simple command line tool to send CAN-frames via CAN_RAW sockets
cangen: CAN frames generator for testing purpose
+
**'''cangen''': CAN frames generator for testing purpose
canplayer: send CAN frames from a file to a CAN interface
+
**'''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:
 
  [armadeus]$ make menuconfig
 
  [armadeus]$ make menuconfig
 
[[Image:Menuconfig_package.png]]
 
[[Image:Menuconfig_package.png]]

Revision as of 10:51, 16 July 2008

Page under construction... Construction.png Informations on this page are not guaranteed !!

Forewords PRELIMINARY VERSION, WORK IN PROGRESS

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 linux-menuconfig
in Device Drivers  ---> SPI support  --->  select <M> Freescale iMX SPI controller as module
in Networking  --->  select <M>   CAN bus subsystem support  as module
in Networking  ---> CAN bus subsystem support -->  select <M> Raw CAN Protocol  as module
in Networking  ---> CAN bus subsystem support -->  select <M> Broadcast Manager CAN Protocol  as module
in Networking  ---> CAN bus subsystem support --> CAN Device Drivers -->  select <M> Virtual Local CAN Interface  as module
in Networking  ---> CAN bus subsystem support --> CAN Device Drivers -->  select <M> Microchip 251x series SPI CAN Controller  as module


Usage

  • load all the needed drivers:
insmod /lib/modules/drivers/spi/spi_imx.ko
insmod /lib/modules/2.6.23.1/kernel/net/can/can.ko
insmod /lib/modules/2.6.23.1/kernel/net/can/candev.ko
insmod /lib/modules/2.6.23.1/kernel/net/can/can-raw.ko
insmod /lib/modules/2.6.23.1/kernel/drivers/net/can/mcp251x.ko

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:
[armadeus]$ make menuconfig

Menuconfig package.png

Menuconfig package net.png

Menuconfig package socketcan.png

Links