Then compile the kernel. The example below is for cross compilation, using a 2 core x86 machine. For compiling on the Pi, just type "make".

Then compile the kernel. The example below is for cross compilation, using a 2 core x86 machine. For compiling on the Pi, just type "make".

<source lang="bash">

<source lang="bash">

+

cd /opt/raspberrypi/linux

make ARCH=arm CROSS_COMPILE=arm-rpi-linux-gnueabi- -j3

make ARCH=arm CROSS_COMPILE=arm-rpi-linux-gnueabi- -j3

</source>

</source>

Revision as of 04:03, 26 August 2013

CAN-bus is a communication protocol used mainly in car and some industrial products.

The Raspberry pi doesn't have CANbus built in, but it can be added through USB or SPI converters.

This document presents how to enable CANbus support in the kernel, using a SPI to CANbus converter (MCP2515). The same can be done for other SPI converters, or for PeakCAN Usb.

Raspbian kernel doesn't come with modules needed, so the kernel must be compiled from source. Refer to http://elinux.org/RPi_Kernel_Compilation for more information on this. The following instructions present all steps requiered to build a kernel with the correct modules, and some useful commands to use it.

Please note:
The best way to compile a kernel is to do it on a Desktop-PC and not on a Raspberry Pi.
It takes about 2 or 3 hours on Desktop-PCs but much more (about 12 hours) on a Raspberry Pi.

If another driver is used, activate it in place of the "MCP251x SPI CAN controllers". If using a USB controller, then SPI support is not needed, but USB must be correctly set up.

Then edit the board definition, to add the informations about the SPI bus, and to configure the interrupt pin of the MCP2515.

vi arch/arm/mach-bcm2708/bcm2708.c
#apply patch

Note that the "IRQF_ONESHOT" flag is only required for kernel 3.6. For kernel 3.2 you should remove it.
Adjust the GPIO pin used for interrupt (here 25), the SPI frequency (here 10MHz) and MCP2515 oscillator frequency (here 20MHz) to your setup.

You should now have the complete new kernel/modules/firmware in the "/opt/raspberrypi/build" directory.
If you want to use it, simply puts its contents to the root directory. It is possible to do it directly without using a temporary build directory, but this method has the advantage of being possible on a remote machine, and to allow easier save of the binary generated (simply archive this directory if you need to give it to someone else).