Template:AkDcanUtils

= CAN Utilities =


 * Since CAN is a "networking" interface and uses the socket layer concepts, many utilities have been developed in open source for utilizing CAN interface.
 * For testing CAN we commonly use the cansend /cangen and candump utilities to send and receive packets via CAN module.
 * To configure the CAN interface netlink standard utilities are used and this requires iproute2 utilities.

Note that if the kernel configuration for "CAN bit-timing calculation" is not enabled then each of the parameters: tq, PROP_SEG etc need to be set individually. When bit-timing calculation is enabled in the kernel then only setting the bitrate is sufficient as it calculates other parameters

ip (route2)
Source for iproute2 is available at fedora project

canutils
canutils build is depends on libsocketcan binaries so build libsocketcan first then proceed to canutils

Source for canutils are available at pengutronix website

Source for libsocketcan is available at pengutronix website

ip cross compilation

 * Modifications

Makefile modifications are needed for cross compiling the source for ARM

Comment these lines from top Makefile, and set appropriate environment variables for building

- DESTDIR=/usr/ + #DESTDIR=/usr/ ROOTDIR=$(DESTDIR) LIBDIR=/usr/lib/

- DBM_INCLUDE:=$(ROOTDIR)/usr/include + #DBM_INCLUDE:=$(ROOTDIR)/usr/include
 * 1) Path to db_185.h include

- CC = gcc + #CC = gcc

Note: Do not build arpd

cp misc/Makefile{,.orig} sed '/^TARGETS/s@arpd@@g' misc/Makefile.orig > misc/Makefile


 * Environment variables

Make sure that TOOL CHAIN path (TOOL_CHAIN_PATH) and target file system (FILESYS_PATH) paths are exported along with these

export GNUEABI=arm-arago-linux-gnueabi export CC=$GNUEABI-gcc export LD=$GNUEABI-ld export NM=$GNUEABI-nm export AR=$GNUEABI-ar export RANLIB=$GNUEABI-ranlib export CXX=$GNUEABI-c++ export PREFIX=$FILESYS_PATH/usr export CROSS_COMPILE_PREFIX=$PREFIX export PATH=$TOOL_CHAIN_PATH/bin:$PATH export DBM_INCLUDE=/usr/include export INCLUDES=/usr/include export DESTDIR=$PREFIX/

./configure --host=arm-arago-linux --prefix=$PREFIX --enable-debug
 * Configuration

make sudo make install
 * Build & Install


 * Move ip executable to correct directory

Above steps will install binary under $FILESYS_PATH/usr/sbin, rename ip to ip.iproute2 and move it to $FILESYS_PATH/sbin/. folder. mv /usr/sbin/ip /sbin/ip.iproute2

libsocketcan cross compilation

 * Environment variables

Make sure that TOOL CHAIN path (TOOL_CHAIN_PATH) and target file system (INSTALL_PATH) paths are exported along with these variables. Example INSTALL_PATH is PWD/install (present working directory is LIBSOCKETCAN_PATH).

Note, create "install" directory under LIBSOCKETCAN_PATH.

export GNUEABI=arm-arago-linux-gnueabi export CC=$GNUEABI-gcc export LD=$GNUEABI-ld export NM=$GNUEABI-nm export AR=$GNUEABI-ar export RANLIB=$GNUEABI-ranlib export CXX=$GNUEABI-c++ export INSTALL_PATH=$PWD export PREFIX=$INSTALL_PATH/ export CROSS_COMPILE_PREFIX=$PREFIX export PATH=$TOOL_CHAIN_PATH/bin:$PATH

./configure --host=arm-arago-linux --prefix=$PREFIX --enable-debug
 * Configuration

make
 * Build

make install
 * Install

canutils cross compilation

 * Environment variables

Make sure that TOOL CHAIN path (TOOL_CHAIN_PATH) and target file system (FILESYS_PATH) paths are exported along with these. Package configuration path (PKG_CONFIG_PATH) should point to libsocketcan config file which is present under libsocketcan source folder (LIBSOCKETCAN_PATH).

export GNUEABI=arm-arago-linux-gnueabi export CC=$GNUEABI-gcc export LD=$GNUEABI-ld export NM=$GNUEABI-nm export AR=$GNUEABI-ar export RANLIB=$GNUEABI-ranlib export CXX=$GNUEABI-c++ export PREFIX=$FILESYS_PATH/usr export CROSS_COMPILE_PREFIX=$PREFIX export PATH=$TOOL_CHAIN_PATH/bin:$PATH export LIBSOCKETCAN_INSTALL_DIR=$LIBSOCKETCAN_PATH/install export PKG_CONFIG_PATH=$LIBSOCKETCAN_PATH/config export LD_LIBRARY_PATH=${LIBDIR}:${LD_LIBRARY_PATH} export LD_RAN_PATH=${LIBDIR}:${LD_RAN_PATH} export LDFLAGS="-Wl,--rpath -Wl,$LIBSOCKETCAN_INSTALL_DIR/lib" export INCLUDES="-I$LIBSOCKETCAN_INSTALL_DIR/include"


 * Configuration

./configure --host=arm-arago-linux --prefix=$PREFIX --enable-debug

make sudo make install
 * Build & Install

ip

 * "ip" utility help - ensure you are using iproute2 utility as only that supports CAN interface.

$ ./ip link help

Usage: ip link add link DEV [ name ] NAME [ txqueuelen PACKETS ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] type TYPE [ ARGS ] ip link delete DEV type TYPE [ ARGS ] ip link set { dev DEVICE | group DEVGROUP } [ { up | down } ] [ arp { on | off } ] [ dynamic { on | off } ] [ multicast { on | off } ] [ allmulticast { on | off } ] [ promisc { on | off } ] [ trailers { on | off } ] [ txqueuelen PACKETS ] [ name NEWNAME ] [ address LLADDR ] [ broadcast LLADDR ] [ mtu MTU ] [ netns PID ] [ alias NAME ] [ vf NUM [ mac LLADDR ] [ vlan VLANID [ qos VLAN-QOS ] ] [ rate TXRATE ] ] [ master DEVICE ] [ nomaster ] ip link show [ DEVICE | group GROUP ] TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | can }

Note: check the result of ip link help ;ensure that the TYPE field contains can

$ ./ip -V ip utility, iproute2-ss110629
 * Ensure you are using the right ip utility (from iproute2)

cansend
$ ./cansend can0 -i 0x10 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 $ ./cansend can0 -i 0x55 0x11 0x22 0x33 0x44 0x55 0x66 0x77 0x88 -e

candump
$ candump can0

cansequence
$ cansequence can0 $ cansequence can0 -p

canconfig
$ canconfig can0 bitrate 100000 $ canconfig can0 start $ canconfig can0 stop $ canconfig can0 ctrlmode loopback on

Description
This template provides DCAN driver usage

Parameters
This template takes no parameter

Example
To use this template simply add the following line to your wiki page.

Here's how it will look in your wiki page: