Esd Can Bus

From Wiki for iCub and Friends
Revision as of 10:54, 23 May 2016 by Straversaro (talk | contribs) (Added instruction to use CAN-USB/2)
Jump to navigation Jump to search

NOTE1: are you looking for installation instruction for the pc104? We provide precompiled device drivers for the pc104. Follow instructions: Section 6.6.



Support for the CAN-USB/2 in Linux is provided by the SocketCAN linux framework.

Once you connect the device to a Linux machine, you can bring up the can network interfaces with the following commands:

$ sudo ip link set can0 type can bitrate 1000000
$ sudo ip link set up can0

For more info, check .




This tutorial is written for the legacy CAN-USB-Mini, for default architecture configuration in use at the IIT, Robotics, Brain and Cognitive Sciences department in 2009, namely Debian unstable, 686 architecture, kernel version 2.6. For different distributions, architectures and kernel versions several "macumbe" (see section "Macumbe") might be needed to compile the drivers successfully.

 cd /usr/src
 tar xfjv esdcan-usb331-linux-x86-3.7.3-k26.tgz

You should now have a directory /usr/src/esdcan-usb331-linux-x86-3.7.3-k26

  • Check you kernel version with command:
uname -a
  • Sudo apt-get kernel heaeders for current kernel and architecture:
sudo apt-get install linux-headers-2.6-686

It is particularly convenient to specify kernel architecture (in our case 686) instead of simply downloading the "generic" version since this operation will later avoid tedious settings. The previous command will naturally result in the kernel headers being downloaded in the /usr/src/linux-header-2.6.21-686 directory. For unexperienced Linux users it is reminded that the previous operation will not interfere with the kernel currently in use.

  • If needed Go to the driver directory:
cd /usr/src/esdcan-usb331-linux-x86-3.7.3-k26

and edit file


This file lists the configuration options for the compilation if the drivers. Having downloaded the correct kernel headers everything should be fine. You might need to set the KERNELPATH variable so that it points to the correct place.

  • It is now possible to make the code:
sudo make

This will result in the following file being created in the driver directory:


In addition we will need the following file:

  1. ntcan.h (the header file)
  2. xxx.a (static library): for example libntcan.a
  3. (dynamic library): for example
  • Copy the dynamic library to the /usr/local/lib directory:
cp /usr/src/esdcan-usb331-linux-x86-3.7.3-k26/lib32/ /usr/local/lib
  • Add symbolic links to the library:
ln /usr/local/lib/ /usr/local/lib/ -s
ln /usr/local/lib/ /usr/local/lib/ -s
  • Go to directory /etc and edit the configuration file for the program ld responsible for loading dynamic libraries:
sudo vim

add line

  • Now update the paths for dynamic libraries:
sudo ldconfig
  • Check if the installation procedure has been successful so far by running program cantest :

At this point the driver is not yet loaded in the system, so the cantest will not run find the device. It is enough however that the program runs correctly (if not it will complain for a missing file).

  • Now load the device driver:
cd /dev
sudo mknod --mode=a+rw can0 c 50 0
sudo mknod --mode=a+rw can1 c 50 1
sudo mknod --mode=a+rw can2 c 50 2
sudo mknod --mode=a+rw can3 c 50 3


the commands:

ls can0
ls can1

should show if everything worked out fine.

  • Now copy the driver file to an apposite folder. For example in the /lib/modules directory:
sudo cp /usr/src/esdcan-usb331-linux-x86-3.7.3-k26/src/esdcan-usb331.ko /lib/modules/2.6.21-1-686/kernel/drivers/usb/misc
  • Run sudo depmod to refresh/update the list of modules known by the system.
  • Check that this was successful by running:
sudo modprobe -l | grep esd-can331 (alternatively sudo modprobe -l | grep esdcan_usb331)

If everything is fine, you should see esd-can331 reported by modprobe.

  • check if the esd-can board is plugged in the usb slot of your computer and hit:
sudo modprobe -i esd-can331
  • Verify that the module is loaded by running lsmod. If the module fails to load

check the troubleshooting section below.

  • Run the cantest program to check that everything worked out fine:

If the installation was successful cantest should report that your device was found.

To load the driver automatically at boot time

If you completed the steps above the driver will NOT be loaded automatically during boot. To configure your machine to load the esd-can module during boot follow these steps.

  • Download the esdcan script
  • copy it in /etc/init.d
  • make sure it access rights are something like (ls -al):
  -rwxr-xr-x   1 root root   471 2007-05-09 23:40 esdcan

Otherwise do:

  sudo chown root esdcan
  sudo chgrp root esdcan
  sudo chmod 755 esdcan
  • now create a symbolic link in /etc/rc2.d:
  cd /etc/rc2.d
  ln -s ../init.d/esdcan S99esdcan

ls -la should show something like this:

  lrwxrwxrwx   1 root root    16 2007-05-09 23:46 S99esdcan -> ../init.d/esdcan

Reboot and do lsmod to check that the module is loaded correctly.


Compile error with kernels >= 2.6.22.

The problem is the "#include <ioctl32.h>" in file esdcan.c. This will be changed in the next Release, as a work around you can delete the line 224 in the esdcan.c :#include <linux/ioctl32.h>

Compile error with kernels 2.6.20 and 2.6.21 For some reasons with some kernels (e.g. we had this problem on kernels 2.6.20 and 2.6.21) the esdcan module fails to load and complains for a missing symbol (paravirt_ops or something close to this). This is caused by the fact that these kernels are *probably* compiled with support for virtualization enabled. The best option is to recompile your kernel, but this fix worked too:

go to /usr/src/esdcan-usb331-linux-x86-3.7.3-k26/src run:

PARAVIRT_OPS=`grep "D paravirt_ops" /boot/ |  colrm 9`

modifying boot/ according to your system (the version of your kernel) and then write:

ld -m elf_i386 --defsym paravirt_ops=0x$PARAVIRT_OPS -r -o esdcan-usb331.ko esdcan-usb331.o esdcan-usb331.mod.o

Then go back top the steps above and install the patched module (.ko file) in your system.

Module loading error with kernels > 2.6.24

The current driver does not support kernels later than 2.6.24.