Friday, February 12, 2010

PEAK CAN Linux drivers

PEAK system provide a number of CAN cards with open-source drivers, and so far they have been working fine for us. (Unlike some other CAN cards!).

Installing the drivers is relatively straight-foward on a clean linux system (a fair bit more complicated with a Xenomai based system), but there are still a few quirks that can get in your way. I've described a simple way that works for us.

Starting with a fresh install of linux, the first thing you probably want to do is add some new users, eg:
adduser (name)
And perhaps add the user to admin group:
sudo usermod -a -G admin (name)
Then you need to make sure gcc, g++ have been installed, and the system is up to date. Having wget and a browser are always handy too. With ubuntu we can use apt:
sudo apt-get update
sudo apt-get install lynx
sudo apt-get install gcc
sudo apt-get install g++
Next, we need to ensure we have our linux header files. Find out your linux version:
uname -r
And install the linux headers, eg:
sudo apt-get install linux-headers-$(uname -r)
Now we need a symbolic link to this for the CAN driver to compile.
So you need to find your linux 'version.h' file. (You can try whereis/locate). eg, mine is at:
/usr/src/linux-headers-2.6.31-14-generic-pae/include/linux/version.h
So you need to make a new symbolic link there:
cd /usr/src
sudo ln -s linux-headers-2.6.31-14-generic-pae linux

We are now ready to compile the driver, but first, we need to get it. Go back to your home directory and download the driver:
cd ~/
wget http://www.peak-system.com/fileadmin/media/linux/files/peak-linux-driver.6.15.tar.gz
Then extract:
tar -xvf peak-linux-driver.6.15.tar.gz
cd peak-linux-driver-6.15
Now we are ready to compile! (and install the libraries)
make clean
make NET=NO

sudo make install
Now we can load the driver (if it isn't already):
cd driver
sudo /sbin/modprobe pcan
And we are all done!

Now, we can check if it is ok:
cat /proc/pcan 
cat /dev/pcan0
cat /dev/pcan1

If you have the dual-channel version you can try sending some data with a terminated CAN cable between the hardware modules. Example:
console1: cat /dev/pcan32
console2: echo "m s 0x111 2 0x12 0x34">/dev/pcan0
console1 will receive:
m s 0x00000111 2  0x12 0x34       310146 619

Enjoy!

6 comments:

Simon Wittber said...

Here are a few shortcuts.

Use "apt-get install build-essential" to install a complete build system.

Then, when building drivers make sure you "apt-get install kernel-package", which you can use to build .deb files for different drivers. Then make sure you build your kernels using "make-kpkg" to keep everything tidy and portable :-)


Regards,

Your friendly local linux dude. :-)

Adrian said...

Thanks Simon!

Also to get networking going edit:
/etc/network/interfaces

eg: for static ip:
auto eth0
iface eth0 inet static
address 192.168.1.201
netmask 255.255.255.0
gateway 192.168.1.1

Restart:
/etc/init.d/networking restart

Adrian said...

The new pcan drivers (.19) need libpopt:
sudo apt-get install libpopt-dev

Adrian said...

If you need to re-discover your network cards (ie: installed a new nic or moved the hdd) type:

delete this:
rm /etc/udev/rules.d/70-persistent-net.rules

reboot

Adrian said...

if you have a problem with ssh authentication just delete ~/.ssh/known_hosts

Adrian said...

Problems with dns?
Edit:
/etc/resolv.conf

example:
nameserver 192.168.1.19
domain ORGNAME.local
search ORGNAME.local

or just set your network to dhcp which will create this file