Integrated CAN solutions for Linux

I just received an email notification from EMS ( that support for their CAN controllers is now in mainline Linux kernels.  The EMS PCI products are supported in 2.6.31, and the CPC-USB product will be supported in 2.6.32.  I’ve used various Linux CAN stacks in the past, but none were as well integrated as the SocketCAN solution that has been merged into the mainline Linux kernel.  Though I’ve not used the EMS products yet, the fact that support is in the mainline kernel source provides a good indication that they know how to do things correctly, and that the software is of good quality.

The Microchip MCP2515 is another option for interfacing CAN with a Linux system, but uses the SPI bus so it typically requires a custom hardware design.   The availability of a USB adapter provides an easy way for CAN to be used with about any existing Linux system including small embedded systems.  From looking at the kernel source code, it appears that EMS solutions use the SJA1000 CAN controller, which has been an industry standard controller for many years.

Message buffering is an important consideration when selecting a Linux CAN solution.  Often in a system, the Linux computer is responsible for data processing, user interface, and other CPU intensive operations.  The real-time control is often relegated to a separate microcontroller.  The CAN bus is then just a convenient and robust way to get data from the control part of the system to the data processing part.  The amount of hardware buffering in the CAN controller determines how quickly the system needs to respond to process the CAN data, so the CAN controller has space to receive new data.  The SJA1000 provides a 64-byte receive fifo, or roughly space for 4 CAN messages.  This provides a little more buffering than the 2 messages in the MCP2515.  Dealing with full bandwidth CAN data in a Linux system can be a challenge  with small amounts of buffering as you typically have to implement the Linux RT patch, and spend some time tuning it.  Another upcoming CAN solution that looks nice is the TI High End CAN Controller (HECC) found in the new Sitara CPUs.  This controller provides 32 hardware mailboxes which should provide even more buffering, which makes it even better suited for operating systems like Linux.  As with any technology, there are tradeoffs, so its nice to have options.

One area the EMS solution may be very useful is for prototyping and development.  The ideal development flow when developing an Embedded Linux product is to development as much as possible on a PC.  The EMS product allows you to easily implement SocketCAN functionality on a PC so you can talk to the rest of your system directly from a PC.  The final embedded solution may be based on a more cost effective solution like the MCP2515 or the TI HECC, but being able to interface to the rest of the system directly from a PC has the potential to improve development efficiency.  This is part of the “Big Win” with Embedded Linux where the same technology scales from the embedded system, to the PC, to the server.


Socketcan utils and test apps added to OpenEmbedded

The Socketcan test applications and utilities are now available in OpenEmbedded.  The socketcan kernel modules already exist in OE.  To build and deploy:

  • get the latest version of OE metadata
  • bitbake socketcan-utils-test
  • scp <oedir>/build/angstrom-2008.1/tmp/deploy/glibc/ipk/<machine>/socketcan-utils-test_0.0+svnr917-r0_armv5te.ipk root@<target IP address>:

And then on the target system:

  • opkg install socketcan-utils-test_0.0+svnr917-r0_armv5te.ipk
  • opkg files socketcan-utils-test

An impressive array of utilities!


Socketcan CAN-bus drivers added to OpenEmbedded

I just added a recipe to OpenEmbedded to build the Socketcan kernel modules from the socketcan SVN.  So if you are using the latest OpenEmbedded metadata, you can:

  • bitbake socketcan-modules
  • scp <oedir>/build/angstrom-2008.1/tmp/deploy/glibc/ipk/<machine>/socketcan-modules_0.0+svnr917-r0_cm-x270.ipk  root@<target IP address>:

and then on the target system:

  • opkg install socketcan-modules_0.0+svnr917-r0_cm-x270.ipk
  • opkg files socketcan-modules
Package socketcan-modules (0.0+svnr917-r0) is installed on root and has the following files:

Then to use the modules:

  • depmod
  • modprobe mcp251x
  • modprobe can-bcm

What is CAN?  Can stands for Controller-area network and is popular in industrial and automotive applications.  A convenient way to add CAN to your Embedded Linux system is with the Microchip MCP2515.  This device connects to a SPI bus which means it can be interfaced with a number of popular SOC’s such as the PXA270, OMAP3, 91SAM9xxx, etc.

More on Socketcan later …

BTW, this recipe really illustrates how easy it is to compile kernel modules outside a kernel in OpenEmbedded:

DESCRIPTION = "Socketcan kernel modules"
SECTION = "kernel/modules"
DEPENDS = "virtual/kernel"
PV = "0.0+svnr${SRCREV}"

SRC_URI = "svn://;module=kernel;proto=svn"

S = "${WORKDIR}/kernel/2.6"

inherit module

This recipe tells OE to download the source, cross-compile it against your target kernel build dir, and then package it for easy install on the device.  This is the way things should work — no messing around figuring out make options, kernel source paths, compiler env variables, etc.