We use cookies on our website to provide you with the best possible service and to further improve our website. By clicking the "Accept all" button, you agree to the use of all cookies. You can limit the cookies used by clicking on "Accept selection". Further information and an option to revoke your selection can be found in our privacy policy.

Necessary:

These cookies are necessary for basic functionality. This allows you to register on our website and forum or order products with our online shop.

Statistics:

With these cookies, we collect anonymized usage data for our website. For example, we can see which content is interesting for our visitors and which resolutions are used. We use the information to optimize our website to provide you with the best possible user experience.

Necessary
Statistics

show more

Linux and PEAK-System's CAN Interfaces

The PEAK-System PC-CAN interfaces product family is fully operational with any Linux OS.

Many Linux distributions, or rather the used Linux kernels, already contain the drivers for PEAK-System's CAN interfaces. The CAN interfaces are then accessed via the common SocketCAN framework as network devices (aka netdev). More information about SocketCAN is available online: SocketCAN documentation.

If you are using Linux environments missing a driver (e.g. minimized Linux environments, older kernels) or you want to use our character-based driver (chardev) e.g. in connection with the PCAN-Basic API, you need our PCAN Driver for Linux package and compile the driver yourself.



Drivers Included in Linux Kernels

Key Features

  • Out-of-the-box usage, suitable for most use cases
  • CAN channels are handled as network devices (SocketCAN)
  • Part of the Linux mainline kernel:

PEAK CAN Interface Kernel Version
PCAN-PCI ≥ 3.2
PCAN-USB, PCAN-USB Pro, PCAN-ExpressCard, PCAN-PCI Express, PCAN-miniPCIe ≥ 3.4
PCAN-cPCI, PCAN-miniPCI, PCAN-PC/104-Plus (Quad), PCAN-PCI/104-Express ≥ 3.7
PCAN-Chip PCIe, PCAN-ExpressCard 34 ≥ 3.17
PCAN-USB FD ≥ 4.0 or ≥ 6.0*
PCAN-USB Pro FD ≥ 4.0
PCAN-USB X6 ≥ 4.9
PCAN-Chip USB ≥ 4.11
PCAN-PCI Express FD ≥ 4.12
PCAN-Chip PCIe FD, PCAN-PCI/104-Express FD, PCAN-miniPCIe FD, PCAN-M.2 ≥ 4.14

* Please note: Some recent versions of the PCAN-USB FD require a Linux kernel ≥ 6.0.
See Check 3 below for further information.



Check 1: Are CAN drivers part of your Linux environment?

Open a terminal and type: grep PEAK_ /boot/config-`uname -r`

All PEAK drivers are listed (y = included in kernel, m = separate module) but this may not work in every Linux environment.


Check 2: Is the CAN device initialized?

Open a terminal and type: lsmod | grep ^peak

If, for example, a USB-based CAN interface from PEAK is connected and initialized, the output will be at least one line starting with peak_usb.


Check 3: Which kernel version is required for your PEAK CAN interface?

We provide a script to check which kernel version is required for running your PEAK CAN interface.

  1. Download the packed script: pcan-kernel-version.sh.tar.gz
  2. To extract it open a terminal and type: tar -xzf pcan-kernel-version.sh.tar.gz
  3. Execute the script with ./pcan-kernel-version.sh

In case of the PCAN-USB FD two kernel version requirements are possible:

Bus 001 Device 003: ID 0c72:0012 PEAK System PCAN-USB FD needs Linux 4.0
Bus 002 Device 002: ID 0c72:0012 PEAK System PCAN-USB FD needs Linux 6.0

USB - CAN Socket Driver: dealing with canX interfaces names under Linux 6.3

Connecting, disconnecting, reconnecting USB - CAN interfaces is convenient since the driver loads itself into memory, but it has the disadvantage that the name of the CAN interfaces depends on the connection order. Using a (so-called) "device id" in this case solves this problem. The device id is a number chosen by the user and flashed in the device itself.

Starting from Linux 6.3, the device id is attached to a CAN channel (unlike Windows where the device id is attached to the device itself). Thus, a PCAN-USB Pro FD will offer to define TWO device ids under Linux while only one will be possible under Windows. To access the flash memory of the USB - CAN interface, one uses the ethtool tool as follows:

To read the flash memory of "can0" interface:

$ sudo ethtool -e can0 raw off
Offset Values
------ ------
0x0000: 00 

To write value "1":

$ sudo ethtool -E can0 value 1

This device id is also readable through the sysfs interface, by displaying the content of the "can_channel_id" file of the concerned CAN network interface:

$ cat /sys/class/net/can0/peak_usb/can_channel_id 
00000001

The purpose of this number is to be used for the naming of the associated CAN interface. This is made possible by the Udev daemon and:

1/ adding a new appropriate rule in (for example) the file "70-persistent-net.rules":

$ cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="peak_usb", KERNEL=="can*", PROGRAM="/bin/peak_usb_device_namer %k", NAME="%c"

2/ adding the following shell script (for example) "/bin/peak_usb_device_namer":

$ cat /bin/peak_usb_device_namer
#!/bin/sh
#
# External Udev program to rename peak_usb CAN interfaces according to the flashed device numbers.
#
# (C) 2023 PEAK-System GmbH by Stephane Grosjean 
#
[ -z "$1" ] && exit 1
CAN_ID="/sys/class/net/$1/peak_usb/can_channel_id"
if [ -f $CAN_ID ]; then
        devid=`cat $CAN_ID`
        # PCAN-USB specific: use "000000FF" instead of "FFFFFFFF" below
        if [ "$devid" != "00000000" -a "$devid" != "FFFFFFFF" ]; then
                printf "can%d\n" 0x${devid}
                exit 0
        fi
fi
echo $1

By convention, the value of the device id when leaving the factory is either 00000000 or FFFFFFFF (000000FF specifically for PCAN-USB). In these specific cases, the above script considers that the CAN interface should not be renamed. Once these changes have been made, the peak_usb driver must be unloaded from memory (if it was previously loaded) and then reloaded:

$ sudo rmmod peak_usb
$ sudo modprobe peak_usb

Driver Package for Proprietary Purposes

Key Features

  • Contains sources for chardev and for netdev drivers
  • Monolithic driver in contrast to mainline SocketCAN environment with several drivers
  • Must be compiled for the target system
  • Can be build for real-time Linux extensions like Xenomai or RTAI (RTDM)
  • Enables the use of PCAN-Basic Linux API calls (not possible via SocketCAN)
  • Provides extra information like the bus load (depending on used CAN interface)
  • Support of specific hardware features
  • True hardware time stamps with handling of clock drifts
  • Mainline kernel drivers are blacklisted when using the PCAN driver

When to Use the Package

  • Your CAN application relies on PCAN-Basic for Linux API (based on chardev driver).
  • The kernel you run is too old to include one of the peak_* mainline drivers you need.
  • The kernel you run includes peak_* mainline drivers that are out-of-date or might contain issues.


Implementation Details Download PCAN Driver Package Documentation

Linux Real Time Drivers for PEAK CAN/CAN FD Interfaces

Since the CAN bus is a real-time network, it obviously may need a real-time system. PEAK-System offers several solutions to support its interfaces in different real-time environments based on the Linux kernel.

But first:

  • "real-time" does not mean "faster". It means "lower and stable latency". Response times may even be a little longer than in a standard Linux kernel, but they will always be the same.
  • Because its nature is to be a packet-oriented protocol, USB is not supported in real-time. The received frames are received in the USB interface which will decide by itself when to transmit them to the host.

As in the standard Linux environment, the choice of the solution depends on the desired application interface:
in standard Linux, if the choice is made according to the chardev or netdev interface, in the real-time world, it is made according to the RTDM or RT-socket-CAN interface. Whatever the chosen interface, the PEAK-System software offer will provide an adapted solution. The table below summarizes this offer:

RT extension Linux-RT Xenomai 3.1 (Mercury skin) Xenomai 3.1 (Cobalt co-kernel) RTAI 5.x
Driver API chardev netdev See linux-rt RTDM RT-Socket-CAN RTDM
PCAN
Driver name PCAN peak_pci PCAN xeno_can_peak_pci PCAN
peak_pciefd xeno_can_peak_pciefd

Linux-RT

Linux-RT is the real-time version of the Linux kernel that brought real-time facilities to the standard kernel (see https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/). Applications don't care about it. Real-time is entirely handled by the patched kernel.

Xenomai

Xenomai is a living project that regularly proposes real-time extensions to the various longterm Linux kernels, for different hardware architectures like ARM, PPC, or x86 (see https://source.denx.de/Xenomai/xenomai/-/wikis/home).

Xenomai 3.1 Mercury is not supported here since it is a simple Xenomai interface (skin) to a Linux-RT patched kernel.

Xenomai 3.1 Cobalt co-kernel is the hard real-time version of Xenomai. Like RTAI, it implements the Real Time Driver Model interface the RT version of the "pcan" driver supports when it is built with "make xeno". Xenomai 3.1 also includes the support of the real-time socket for the CAN bus (aka "RT-Socket-CAN"). With the driver "xeno_can_peak_pci", the RT-Socket-CAN core natively includes support of all the PCI/PCIe CAN 2.0 interfaces of PEAK-System.

The PCIe CAN FD interfaces family is natively supported by the driver "xeno_can_peak_pciefd" since Xenomai v3.2 in CAN 2.0 mode *ONLY* (at the time this note is written - 2021-11-15 - CAN FD is not yet supported by the RT-Socket-CAN core).

To take advantage of real-time under Xenomai, an application must be compiled and linked with the real-time libraries that offer access to the real-time facilities added by the Xenomai extension. That's the reason why the pcan library (which encapsulates the calls to the kernel entry points) must be compiled in real-time mode too.

Finally, as shown in the table above, RT-Socket-CAN is not supported by the "pcan" driver.

RTAI

RTAI is another Linux kernel extension coming with user libraries and RTDM API that also supports different hardware architectures like ARM, PPC, x86, and m68k (see https://www.rtai.org/).

Unlike Xenomai, RTAI doesn't propose any native support of real-time CAN sockets. Therefore, the RTDM version of the "pcan" driver and its library (built with "make rtai") is the only way to take advantage of the benefits brought by real-time under RTAI when using the PC CAN interfaces of PEAK-System.

Known Issue in RTAI 5.3

About RTAI 5.3 (release date: May 19, 2021): the x86 version of the base modules prevents the pcan driver to run correctly. This is a confirmed bug in RTAI 5.3 (only) that must be manually fixed until a new version of RTAI 5 is delivered:

  1. edit "base/arch/x86/hal/hal.c"
  2. Change line 373 (function "rt_set_irq_ack()") to add the missing "!":

    if (irq >= RTAI_NR_IRQS || !(desc = &rtai_irq_desc(irq))) {

  3. Save and exit
  4. Rebuild (make) and install (sudo make install) RTAI
  5. Reload the new RTAI modules

PCAN-Basic for Linux

API for Connecting to CAN and CAN FD Buses

We provide the PCAN-Basic API to allow the development of your own CAN applications for Linux. Programmers can use the languages C++, Java, and Python 3.x. More information about PCAN-Basic is available at its product web page.


Warning: this archive file SHOULD NOT be uncompressed nor installed from the PCAN driver own directory. Please uncompress and install it from any other directory than "peak-linux-driver-x.y.z". The source files contained in it cannot replace those provided by the peak-linux-driver-x.y.z package.


System requirements: This API requires the chardev driver. Please use the Driver Package for Proprietary Purposes.



PCAN-Basic Product Page Download Version History

PCAN-View for Linux

Software for Displaying CAN and CAN FD Messages

PCAN-View is a simple CAN monitor software for receiving and transmitting CAN and CAN FD messages. PCAN-View for Linux is based on the NCurses library.

System requirements: This software requires the chardev driver. Please use the Driver Package for Proprietary Purposes.


How to install PCAN-View via repository

Installing software through repository needs first to register the repository only once. Next to the first installation of the software, there is nothing you have to do, except installing available updates when prompted by your system.

Debian-based Linux distributions

Download and install the following file peak-system.list from the PEAK-System website:

$ wget -q http://www.peak-system.com/debian/dists/`lsb_release -cs`/peak-system.list -O- | sudo tee /etc/apt/sources.list.d/peak-system.list

Note: If the lsb_release tool is not installed on your Linux system then replace `lsb_release -cs` by the name of your Linux distribution. For example:

$ wget -q http://www.peak-system.com/debian/dists/wheezy/peak-system.list -O- | sudo tee /etc/apt/sources.list.d/peak-system.list

Then, download and install the PEAK-System public key for apt-secure, so that the repository is trusted:

$ wget -q http://www.peak-system.com/debian/peak-system-public-key.asc -O- | sudo apt-key add -

To install pcanview-ncurses next, do:

$ sudo apt-get update
$ sudo apt-get install pcanview-ncurses

The supported architectures are summarized in the table below:
amd64 i386 arm64 armhf ppc64el
Ubuntu:
Trusty 14.04 LTS
Xenial 16.04 LTS
Bionic 18.04 LTS
Cosmic 18.10
Disco 19.04
Eoan 19.10
Focal 20.04 LTS
Groovy 20.10
Hirsute 21.04
Jammy 22.04 LTS
OpenSUSE Tumbleweed see Xenial

Debian:
Wheezy 7.11
Jessie 8.11
Stretch 9.9
Buster 10
Bullseye 11
Bookworm 12