How to configure and use CAN bus

From RidgeRun Developer Connection

Revision as of 01:06, 22 December 2010 by Tfischer (Talk | contribs)
Jump to:navigation, search

This article explains how to enable the CAN bus using as examples the AM35x EVM and [[:Category:OMAP35x OMAP35x], but can be applied to other platforms as well. In addition, steps to exchange data with a MCP2515 Bus Monitor board is also documented.

Contents

Enable the CAN controller kernel driver

AM35x kernel

In the case of the Category:AM35x platform the configuration is:

Linux Kernel Configuration
     Networking support
        CAN bus subsystem support
           CAN device drivers
               Platform CAN drivers with Netlink support
                 CAN bit-timing calculation
                 TI High End CAN controller (HECC)

OMAP3x kernel

In the case of the Category:OMAP3x platform with a MCP2515 chip the configuration is:

Linux Kernel Configuration
     Networking support
        CAN bus subsystem support
           CAN device drivers
               Platform CAN drivers with Netlink support
                 CAN bit-timing calculation
                 Microchip MCP251x SPI CAN controller


Enable socketcan and ip tools

Working with the CAN bus requires enabling the 'ip' tools from iproute2 package (the 'ip' tool from busybox won't work). The socketcan package is optional and provide you with tools to debug your can bus.

These packages are available for selection from the RidgeRun SDK in the configuration menu.

 File System Configuration
   Select target's file system software
     iproute2-2.6.34 
     socketcan utils

Setup the networking rules

Edit your /etc/networking/interfaces on the target file system and add the following rules (required to setup the bit-rate of the bus):

auto can0
iface can0 inet manual
	#pre-up ip link set $IFACE type can bitrate 125000 listen-only off
	pre-up /ip link set $IFACE type can bitrate 125000 triple-sampling on
	up /sbin/ifconfig $IFACE up
	down /sbin/ifconfig $IFACE down

Verifying CAN support configuration

modprobe can
modprobe can-dev
modprobe can-raw
modprobe mcp251x

Linux boot

Look for the following in the Linux boot output

Run

dmesg | fgrep -i can

Expected output:

CAN device driver interface
can: controller area network core (rev 20090105 abi 8)

sysfs entries

Verify the CAN host driver is registered correctly (meaning properly added to kernel arch/arm/mach-*/board-*.c file).

MC2515

Run:

ls -d /sys/bus/spi/drivers/mcp251x
cat /sys/devices/platform/omap2_mcspi.1/spi1.0/modalias

Expect:

/sys/bus/spi/drivers/mcp251x
mcp2515

References

Navigation
Toolbox