Below are working steps to get a reliable CanBus working on the PI by cross compiling with Ubuntu. I use it with CoDeSys run-time which has a full CanOpen Master/Slave, J1939 Manager, and DeviceNet Scanner.
http://store.codesys.com/codesys-contro ... pi-sl.html
###Working directory for compiling and files
export WORKING_DIR=${HOME}/rpi2
###Number of processors to use during compiling (N+1)
export NUM_PROCESSORS=5
###PI IP ADDRESS
export PI_IP=192.168.10.104
###PI USERNAME
export PI_USER=root
###Get Required APPS to compile
sudo apt-get install gcc-arm-linux-gnueabi make ncurses-dev git dh-autoreconf
###Required of 64bit OS
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0
###Make direcotry for source files and compiler
cd ${HOME}
sudo mkdir -p $WORKING_DIR
cd $WORKING_DIR
sudo chmod og+w .
###Get the Get the kernel source
git clone
https://github.com/raspberrypi/linux.git
###Get the Get cross compiler tools
git clone --depth 1 git://github.com/raspberrypi/tools.git
export KERNEL_SRC=$WORKING_DIR/linux
###Get config.gz from RPI copy to kernel source
scp root@192.168.10.104:/proc/config.gz config.gz
zcat config.gz > .config
mv .config $KERNEL_SRC
###Change to Kernel source DIR
cd $KERNEL_SRC
###Set KERNEL VERSION FOR REST OF Command
export KERNEL_VER=$(make kernelversion)
###Compile new Config
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- oldconfig -j${NUM_PROCESSORS}
####Make any new changes in kernel settings
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig -j${NUM_PROCESSORS}
#Activate the following lines:
#
#[*] Networking support --->
#....<M> CAN bus subsystem support --->
#........<M> Raw CAN Protocol (raw access with CAN-ID filtering)
#........<M> Broadcast Manager CAN Protocol (with content filtering)
#............CAN Device Drivers --->
#................<M> Platform CAN drivers with Netlink support
#................[*] CAN bit-timing calculation
#................<M> Microchip MCP251x SPI CAN controllers
#................[*] CAN devices debugging messages
#
#....Device Drivers --->
#........[*] SPI support --->
#............<M> BCM2798 SPI controller driver (SPI0)
#............<M> User mode SPI driver support
#.......-*- GPIO Support --->
#............[*] /sys/class/gpio/... (sysfs interface)
####build the kernel
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j${NUM_PROCESSORS}
cd ${WORKING_DIR}/tools/mkimage
./imagetool-uncompressed.py ../../linux/arch/arm/boot/zImage
mkdir -p ${WORKING_DIR}/build/boot
mv kernel.img ${WORKING_DIR}/build/boot
####generate a directory containing kernel modules
cd $KERNEL_SRC
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install INSTALL_MOD_PATH=${WORKING_DIR}/build/ -j5
####Make spi-bcm2708
cd ${WORKING_DIR}
git clone
https://github.com/notro/spi-bcm2708
cd ${WORKING_DIR}/spi-bcm2708
sudo sed -i 's#KDIR := /lib/modules/$(shell uname -r)/build#KDIR := ${KERNEL_SRC}#' Makefile
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
cp spi-bcm2708.ko ${WORKING_DIR}/build/lib/modules/${KERNEL_VER}+/kernel/drivers/spi
####Make spi-config
cd ${WORKING_DIR}
git clone
https://github.com/msperl/spi-config
cd ${WORKING_DIR}/spi-config
sudo sed -i 's#KDIR := /lib/modules/$(shell uname -r)/build#KDIR := ${KERNEL_SRC}#' Makefile
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
cp spi-config.ko ${WORKING_DIR}/build/lib/modules/${KERNEL_VER}+/extra
####Make mcp2515
cd ${WORKING_DIR}
cd MCP2515
git clone
https://github.com/jzhvymetal/MCP2515
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- XTRA="KBUILD_EXTRA_SYMBOLS=$KERNEL_SRC/drivers/net/can/Module.symvers" M=${WORKING_DIR}/MCP2515
cp mcp2515.ko ${WORKING_DIR}/build/lib/modules/${KERNEL_VER}+/kernel/drivers/net/can
###Make Can user tools
cd ${WORKING_DIR}
####////CAN NOT GET CANUTILS TO CROSSCOMPILE
#git clone git://gitorious.org/linux-can/can-utils.git
#cd can-utils
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install DESTDIR=${WORKING_DIR}/build/usr PREFIX= -j5
###///NEEDS UPDATING ONCE CANUTILS CAN BE CROSS COMPILED
git clone
https://github.com/jzhvymetal/canutil_pi
cd canutil_pi
mkdir -p ${WORKING_DIR}/build/usr/bin
cp * ${WORKING_DIR}/build/usr/bin
##Compress Updates and upload to PI
cd ${WORKING_DIR}/build
sudo tar czf updates.tgz *
scp updates.tgz ${PI_USER}@${PI_IP}:/tmp
#####Connect to your Raspberry PI over SSH
ssh ${PI_USER}@${PI_IP}
####Apply updates
cd /; sudo tar xvf /tmp/updates.tgz # you normally should'nt do that
sudo depmod -a
####Enable CAN in CoDeSys
nano /etc/CODESYSControl.cfg
####Add lines Below
[ComponentManager]
Component.1=CmpOpenSSL
Component.2=CmpCAACanL2
Component.3=CmpCAASdoServer
Component.4=CmpCAASdoClient
Component.5=CmpSocketCanDrv
####Exit and save ctrl+x
###reboot for new kernel to take effect
reboot
###Start Can On PI
sudo insmod /lib/modules/3.12.28+//kernel/drivers/spi/spi-bcm2708.ko realtime
sudo insmod /lib/modules/3.12.28+/kernel/net/can/can.ko
sudo insmod /lib/modules/3.12.28+/kernel/drivers/net/can/can-dev.ko
sudo insmod /lib/modules/3.12.28+/kernel/net/can/can-raw.ko
sudo insmod /lib/modules/3.12.28+/kernel/net/can/can-bcm.ko
sudo insmod /lib/modules/3.12.28+/extra/spi-config.ko devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
sudo insmod /lib/modules/3.12.28+/kernel/drivers/net/can/mcp2515.ko
ip link set can0 up type can bitrate 250000 restart-ms 100 triple-sampling on
service codesyscontrol start