GUIDE: PCAN-LINUX on Raspbian / Raspberry PI OS

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
M.Heidemann
Sales & Support
Sales & Support
Posts: 1021
Joined: Fri 20. Sep 2019, 13:31

GUIDE: PCAN-LINUX on Raspbian / Raspberry PI OS

Post by M.Heidemann » Wed 2. Feb 2022, 14:29

GUIDE: PCAN-LINUX on Raspbian / Raspberry PI OS

We have alot of customers that want to use their USB based PCAN-interfaces on a Raspberry PI, specifically
using Raspbian / Raspberry PI OS.

Our Interfaces can either be used as character devices (CharDev) with our proprietary APIs (Such as PCANBasic, CAN2.0 API, CAN FD API) or as network devices (NetDev) using the SocketCAN API.

This guide will outline the necessary steps for both.

PCAN-APIs (CharDev)

Here a small guide which we have tested on a RPI 4 with the 2019-07-10-raspbian-buster.img:

Download the latest raspbian image and install it on a sd card using Win32DiskImager or any other tool
boot your RPI, and setup all necessary settings (language, network etc.)
now update your PI to the latest version and reboot once:

Code: Select all

$ sudo apt get update

Code: Select all

$ sudo apt get upgrade

Code: Select all

$ reboot
install the kernel headers:

Code: Select all

$ sudo apt-get install raspberrypi-kernel-headers
install libpopt-dev:

Code: Select all

$ sudo apt-get install libpopt-dev
Now download the peak-linux driver-8.14 (or newer) from our linux website and put it into the /home/pi directory:

Link PCAN-Linux Page:

http://www.peak-system.com/fileadmin/me ... /index.htm

Untar the package:

Code: Select all

$ tar -xzf peak-linux-driver-8.14.0.tar.gz
Change into the extracted PCAN-Linux driver folder:

Code: Select all

$ cd peak-linux-driver-8.14.0
Clean up the build directory:

Code: Select all

$ make clean
Build PCAN-driver as CharDev:

Code: Select all

$ make PCC=NO PCI=NO ISA=NO DNG=NO
Note: If you use a Raspberry Pi Compute Module and need PCI/PCIe-support, remove the "PCI=NO" option.

Install Driver:

Code: Select all

$ sudo make install
Load the driver:

Code: Select all

$ sudo modprobe pcan
Show all connected PCAN-USB devices:

Code: Select all

$ cat /proc/pcan
You can now use all chardev tools and libs to work with the PCAN-USB devices,
the usage is explained in details in the PCAN-Linux documentation, chaper 4 -"Usage of the Driver"

Link PCAN-Linux Documentation:

http://www.peak-system.com/fileadmin/me ... an_eng.pdf

SocketCAN (NetDev)

The mainline-kernel drivers for PCAN-Interfaces are included in the latest Raspberry PI OS releases,
we were able to confirm this being the case for the following releases:

Current Raspberry PI OS Releases:
  • Raspberry PI OS based on Debian 11 (2022-01-28-raspios-bullseye)
  • Raspberry PI OS based on Debain 10 (2022-01-28-raspios-buster) - Legacy
In this case no further installation is required, the PCAN-devices will be directly available
via "ip link", enumerated in ascending order as can0, can1, etc.

For information on how to use the devices, please scroll down to the USAGE ScoketCAN section below:

Older Raspbian / Raspberry PI OS Releases:

Older version of Raspbian /Raspberry PI OS do not include the mainline-kernel drivers
and need additional steps to use your USB-based PCAN-interfaces with SocketCAN:

Here a small guide which we have tested on a RPI 4 with the 2019-07-10-raspbian-buster.img:

Download the latest raspbian image and install it on a sd card using Win32DiskImager or any other tool
boot your RPI, and setup all necessary settings (language, network etc.)
now update your PI to the latest version and reboot once:

Code: Select all

$ sudo apt get update

Code: Select all

$ sudo apt get upgrade

Code: Select all

$ reboot
install the kernel headers:

Code: Select all

$ sudo apt-get install raspberrypi-kernel-headers
install libpopt-dev:

Code: Select all

$ sudo apt-get install libpopt-dev
Now download the peak-linux driver-8.14 (or newer) from our linux website and put it into the /home/pi directory:

Link PCAN-Linux Page:

http://www.peak-system.com/fileadmin/me ... /index.htm

Untar the package:

Code: Select all

$ tar -xzf peak-linux-driver-8.14.0.tar.gz
Change into the extracted PCAN-Linux driver folder:

Code: Select all

$ cd peak-linux-driver-8.14.0
Clean up the build directory:

Code: Select all

$ make clean
Build driver as NetDev:

Code: Select all

$ make PCC=NO PCI=NO ISA=NO DNG=NO NET=NETDEV_SUPPORT
Note: If you use a Raspberry Pi Compute Module and need PCI/PCIe-support, remove the "PCI=NO" option.

Install the driver:

Code: Select all

$ sudo make install
Load the driver:

Code: Select all

$ sudo modprobe pcan
show all connected PCAN-USB as canX devices

Code: Select all

$ cat /proc/pcan

You can now proceed with using the devices with SocketCAN as described below:

USAGE SocketCAN

Using "ip link" the devices will be listed as can0, can1 in ascending order:

Code: Select all

pi@raspberrypi:~ $ ip link ls
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DORMANT group default qlen 1000
    link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff
4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can
From there the devices can be set up using the "ip link"-utility and be used with - for example - the can-utils package (which includes cansend, cangen, etc)

In case you want to install the can-utils:

Code: Select all

pi@raspberrypi:~ sudo apt-get install can-utils
Setting up the device@500kbit/s via "ip link":

Code: Select all

pi@raspberrypi:~ $ sudo ip link set can0 up type can bitrate 500000
You can then proceed to use the device with -for example -candump:

Code: Select all

pi@raspberrypi:~ $ candump can0
  can0  100   [8]  50 43 41 4E 2D 55 53 42
  can0  101   [8]  75 73 65 64 20 6F 6E 20
  can0  102   [8]  52 61 73 70 69 6F 73 21


We hope this guide will help you getting started with using your PCAN-USB inteface
on Raspberry PI.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply