Full PCAN-USB (pro) FD support in Linux 4.0

CAN FD Interface for High-Speed USB 2.0
Post Reply
User avatar
O.Hartkopp
Posts: 40
Joined: Fri 22. Nov 2013, 19:47

Full PCAN-USB (pro) FD support in Linux 4.0

Post by O.Hartkopp » Sat 28. Mar 2015, 20:11

Stephane Grosjean from PEAK System contributed the CAN FD driver for PCAN-USB FD and PCAN-USB pro FD for the next Linux Kernel 4.0.

The several patches for the upgrade from the PCAN USB to the FD enabled drivers can be seen here: http://git.kernel.org/cgit/linux/kernel ... b/peak_usb

The configuration of the PCAN USB (pro) FD adapters can be done with the latest 'ip' tool from the iproute2 package which is part of all Linux distributions (examples see below).

The PCAN USB FD adapters support the ISO/non-ISO CAN FD frame format which can be configured for each CAN channel (using the Linux driver and a CAN USB FD firmware 2.x).

Example for setting a PCAN USB FD with an arbitration bitrate of 125 kbit/s and a data bitrate of 8 Mbit/s (both having a sampling-point at 80%):

Code: Select all

# ip link set can0 type can bitrate 125000 sample-point 0.800 dbitrate 8000000 dsample-point 0.800 fd on
# ip link set can0 up
# ip -det link show can0
11: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can promiscuity 0
can <FD> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 125000 sample-point 0.800
tq 100 prop-seg 31 phase-seg1 32 phase-seg2 16 sjw 1
pcan_usb_fd: tseg1 1..64 tseg2 1..16 sjw 1..16 brp 1..1024 brp-inc 1
dbitrate 8000000 dsample-point 0.800
dtq 12 dprop-seg 3 dphase-seg1 4 dphase-seg2 2 dsjw 1
pcan_usb_fd: dtseg1 1..16 dtseg2 1..8 dsjw 1..4 dbrp 1..1024 dbrp-inc 1
clock 80000000
# _
With firmware 2.x the CAN FD ISO mode is the default. To set the PCAN USB FD controller to the non-ISO mode the switch "fd-non-iso on" has to be added:

Code: Select all

# ip link set can0 type can bitrate 125000 sample-point 0.800 dbitrate 8000000 dsample-point 0.800 fd on fd-non-iso on
# ip link set can0 up
# ip -det link show can0
11: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 72 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can promiscuity 0
can <FD,FD-NON-ISO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 125000 sample-point 0.800
tq 100 prop-seg 31 phase-seg1 32 phase-seg2 16 sjw 1
pcan_usb_fd: tseg1 1..64 tseg2 1..16 sjw 1..16 brp 1..1024 brp-inc 1
dbitrate 8000000 dsample-point 0.800
dtq 12 dprop-seg 3 dphase-seg1 4 dphase-seg2 2 dsjw 1
pcan_usb_fd: dtseg1 1..16 dtseg2 1..8 dsjw 1..4 dbrp 1..1024 dbrp-inc 1
clock 80000000
# _
Please note that with firmware 1.x the FD-NON-ISO flag is always set and can not be changed as firmware 1.x only implements the non-ISO CAN FD protocol. So upgrading the fimrware is recommended ;)

Best regards,
Oliver

nexulm
Posts: 2
Joined: Wed 1. Apr 2015, 13:28

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by nexulm » Wed 1. Apr 2015, 15:55

Hello Oliver,

thanks for this missing hint for me.
I was struggling around with the PCAN-USB Pro FD within the last days on my ODROID-W (Raspberry Pi based). As the latest Rasbian version I'm using is based on Kernel 3.18.9 I was not 100% sure why the interface wasn't working properly.
After compiling and using the the latest Peak-System Linux Driver v7.14 the PCAN-USB pro FD was detected fine and usable but without CAN-FD capability. While using the CAN-FD stuff with latest self compiled iproute2...
ip link set can0 type can bitrate 125000 sample-point 0.800 dbitrate 8000000 dsample-point 0.800 fd on
...the following error occurs:
RTNETLINK answers: Operation not supported.

Today I've patched my RaspberryPi kernel source v3.18.9 tree "../net/can" with the latest mainline Kernel 4.0rc6, uninstall the Peak-System driver v7.14 again and now I'm using the peak_usb module from the Linux Kernel with success.

The PCAN-USB pro FD seems to run now without problems on my ODROID-W with patched Kernel 3.18.9 and self compiled ip-route2.

can2 123 [64] 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF 00 00 00

Regards
Michael

stahlstngel
Posts: 10
Joined: Thu 28. Apr 2016, 18:24

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by stahlstngel » Thu 19. May 2016, 14:36

Hello,

- i upgraded the firmware to 2.2.1
- $ uname -r: 4.1.19-v7+
- i installed the drivers for socketcan (8.0.20)
- the platform is a Raspberry Pi 3

and my problem is that the "fd-non-iso" option is not available. So what am i doing wrong?

Code: Select all

$ sudo ip link set can0 up type can bitrate 500000 dbitrate 2000000 fd on fd-non-iso on
can: unknown option "fd-non-iso"

Usage: ip link set DEVICE type can
	[ bitrate BITRATE [ sample-point SAMPLE-POINT] ] | 
	[ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1
 	  phase-seg2 PHASE-SEG2 [ sjw SJW ] ]

	[ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] | 
	[ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1
 	  dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]

	[ loopback { on | off } ]
	[ listen-only { on | off } ]
	[ triple-sampling { on | off } ]
	[ one-shot { on | off } ]
	[ berr-reporting { on | off } ]
	[ fd { on | off } ]

	[ restart-ms TIME-MS ]
	[ restart ]

	Where: BITRATE	:= { 1..1000000 }
		  SAMPLE-POINT	:= { 0.000..0.999 }
		  TQ		:= { NUMBER }
		  PROP-SEG	:= { 1..8 }
		  PHASE-SEG1	:= { 1..8 }
		  PHASE-SEG2	:= { 1..8 }
		  SJW		:= { 1..4 }
		  RESTART-MS	:= { 0 | NUMBER }

M.Maidhof
Support
Support
Posts: 1753
Joined: Wed 22. Sep 2010, 14:00

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by M.Maidhof » Thu 19. May 2016, 15:54

Hi,

please use the kernel driver which is included in the 4.1 kernel version for SocketCAN, instead of using the 8.0.20-beta peak-linux driver. The peak-linux driver should be used for chardev applications only.

With "make uninstall" and a reboot, you will be able to use the kernel driver again, which should offer that feature.

best regards

Michael

stahlstngel
Posts: 10
Joined: Thu 28. Apr 2016, 18:24

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by stahlstngel » Thu 19. May 2016, 16:25

Hey,

so...mhh....my problem before was that my kernel does not support the SocketCAN option.
For this reason i installed the peak driver (by using the the linux-header) to enable the SocketCAN option.

So how do i install the "4.1 kernel version for SocketCAN"?

User avatar
O.Hartkopp
Posts: 40
Joined: Fri 22. Nov 2013, 19:47

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by O.Hartkopp » Thu 19. May 2016, 20:30

stahlstngel wrote: my problem before was that my kernel does not support the SocketCAN option.
What kind of OS are you using for your Raspi3????

The Raspian Images are Debian based where CONFIG_CAN and friends are enabled by default.
stahlstngel wrote: For this reason i installed the peak driver (by using the the linux-header) to enable the SocketCAN option.
Installing the linux-headers does not change the the kernel config nor the functionality of the installed kernel.
stahlstngel wrote: So how do i install the "4.1 kernel version for SocketCAN"?
Just took a look at the Raspi Kernel config:
https://github.com/raspberrypi/linux/bl ... _defconfig

It enables

Code: Select all

CONFIG_CAN=m
CONFIG_CAN_VCAN=m
CONFIG_CAN_MCP251X=m
But no USB CAN adapters :(

You probably need to compile a Kernel on your own where you can enable the missing CAN driers and protocols on your own:

http://elinux.org/RPi_Kernel_Compilation

Regards,
Oliver

stahlstngel
Posts: 10
Joined: Thu 28. Apr 2016, 18:24

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by stahlstngel » Fri 20. May 2016, 10:21

What kind of OS are you using for your Raspi3????
I using the Raspian image from raspberrypi.org.
The Raspian Images are Debian based where CONFIG_CAN and friends are enabled by default.
I could not check the Kernel options on the RPi, because there is no /boot/config-$(uname -r).
Installing the linux-headers does not change the the kernel config nor the functionality of the installed kernel.
But the linux-headers are needed to install the peak-driver.


Than i checked a other PC with the kernel 3.13.0-85-generic (>3.6) and checked the kernel parameter ( see [1]).
So is seems that everything is okay.....but after plug-in the USB there is no "can0".

So what needs to be done to get the "kernel driver" working with the adapter?



[1]

Code: Select all

$ grep "CONFIG_CAN" /boot/config-`uname -r`
CONFIG_CAN=m
CONFIG_CAN_RAW=m
CONFIG_CAN_BCM=m
CONFIG_CAN_GW=m
CONFIG_CAN_VCAN=m
CONFIG_CAN_SLCAN=m
CONFIG_CAN_DEV=m
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_LEDS=y
CONFIG_CAN_MCP251X=m
CONFIG_CAN_JANZ_ICAN3=m
CONFIG_CAN_SJA1000=m
CONFIG_CAN_SJA1000_ISA=m
CONFIG_CAN_SJA1000_PLATFORM=m
CONFIG_CAN_EMS_PCMCIA=m
CONFIG_CAN_EMS_PCI=m
CONFIG_CAN_PEAK_PCMCIA=m
CONFIG_CAN_PEAK_PCI=m
CONFIG_CAN_PEAK_PCIEC=y
CONFIG_CAN_KVASER_PCI=m
CONFIG_CAN_PLX_PCI=m
CONFIG_CAN_C_CAN=m
CONFIG_CAN_C_CAN_PLATFORM=m
CONFIG_CAN_C_CAN_PCI=m
CONFIG_CAN_CC770=m
CONFIG_CAN_CC770_ISA=m
CONFIG_CAN_CC770_PLATFORM=m
CONFIG_CAN_EMS_USB=m
CONFIG_CAN_ESD_USB2=m
CONFIG_CAN_KVASER_USB=m
CONFIG_CAN_PEAK_USB=m
CONFIG_CAN_8DEV_USB=m
CONFIG_CAN_SOFTING=m
CONFIG_CAN_SOFTING_CS=m
# CONFIG_CAN_DEBUG_DEVICES is not set

User avatar
O.Hartkopp
Posts: 40
Joined: Fri 22. Nov 2013, 19:47

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by O.Hartkopp » Fri 20. May 2016, 12:58

stahlstngel wrote:Than i checked a other PC with the kernel 3.13.0-85-generic (>3.6) and checked the kernel parameter ( see [1]).
So is seems that everything is okay.....but after plug-in the USB there is no "can0".

So what needs to be done to get the "kernel driver" working with the adapter?



[1]

Code: Select all

$ grep "CONFIG_CAN" /boot/config-`uname -r`
CONFIG_CAN=m
CONFIG_CAN_RAW=m
CONFIG_CAN_BCM=m
CONFIG_CAN_GW=m
CONFIG_CAN_VCAN=m
CONFIG_CAN_SLCAN=m
CONFIG_CAN_DEV=m
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_LEDS=y
CONFIG_CAN_MCP251X=m
CONFIG_CAN_JANZ_ICAN3=m
CONFIG_CAN_SJA1000=m
CONFIG_CAN_SJA1000_ISA=m
CONFIG_CAN_SJA1000_PLATFORM=m
CONFIG_CAN_EMS_PCMCIA=m
CONFIG_CAN_EMS_PCI=m
CONFIG_CAN_PEAK_PCMCIA=m
CONFIG_CAN_PEAK_PCI=m
CONFIG_CAN_PEAK_PCIEC=y
CONFIG_CAN_KVASER_PCI=m
CONFIG_CAN_PLX_PCI=m
CONFIG_CAN_C_CAN=m
CONFIG_CAN_C_CAN_PLATFORM=m
CONFIG_CAN_C_CAN_PCI=m
CONFIG_CAN_CC770=m
CONFIG_CAN_CC770_ISA=m
CONFIG_CAN_CC770_PLATFORM=m
CONFIG_CAN_EMS_USB=m
CONFIG_CAN_ESD_USB2=m
CONFIG_CAN_KVASER_USB=m
CONFIG_CAN_PEAK_USB=m
CONFIG_CAN_8DEV_USB=m
CONFIG_CAN_SOFTING=m
CONFIG_CAN_SOFTING_CS=m
# CONFIG_CAN_DEBUG_DEVICES is not set
Ok. The question is answered by the headline of this thread:
"Full PCAN-USB (pro) FD support in Linux 4.0"

When you run a 3.13.0-85-generic there is CAN FD Support for vcan and network layer (since Linux 3.6):
http://can-newsletter.org/engineering/s ... 3.6_120703

But the driver infrastructure for handling CAN FD interfaces just emerged in 3.15:
http://can-newsletter.org/engineering/s ... re_peak_vw

And based on this infrastructure the PCAN USB FD adapters emerged in Linux 4.0.

There are many descriptions how to update the Raspi Kernel to Linux 4.0+ on the Internet.

Linux 3.13 will not work - as long as you don't want to apply all the Linux CAN driver patches that were posted since 3.13 by hand.

Regards,
Oliver

stahlstngel
Posts: 10
Joined: Thu 28. Apr 2016, 18:24

Re: Full PCAN-USB (pro) FD support in Linux 4.0

Post by stahlstngel » Mon 30. May 2016, 22:56

Indeed. On my DesktopPC can0 showed up after a kernel update to 4.2, but no "ISO-CAN-FD" support (fd-non-iso on)--> see [1]

To get "can0" on the Raspberry pi it was necessary to compile the kernel again. But also here no "ISO-CAN-FD" support --> see also [1]

way to compile the RPi kernel:

Code: Select all

# source: https://www.raspberrypi.org/documentation/linux/kernel/building.md

$:
cd
git clone --depth=1 https://github.com/raspberrypi/linux
cd linux

# install dependencies
sudo apt-get install bc
sudo apt-get install libncurses5-dev

# Raspberry Pi 2/3 Default Build Configuration
KERNEL=kernel7
make bcm2709_defconfig
make menuconfig
--> config parameters
--> check [A]

# build kernel
make -j4 zImage modules dtbs
sudo make modules_install
sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
#sudo scripts/mkknlimg arch/arm/boot/zImage /boot/$KERNEL.img
sudo scripts/mkknlimg arch/arm/boot/zImage /boot/can_kernel.img


[A]
$ grep "^CONFIG_CAN" .config
CONFIG_CAN=m
CONFIG_CAN_RAW=m
CONFIG_CAN_BCM=m
CONFIG_CAN_GW=m
CONFIG_CAN_VCAN=m
CONFIG_CAN_DEV=m
CONFIG_CAN_CALC_BITTIMING=y
CONFIG_CAN_LEDS=y
CONFIG_CAN_MCP251X=m
CONFIG_CAN_PEAK_USB=m
CONFIG_CAN_DEBUG_DEVICES=y
[1]
iproute2 (iproute2-ss140804) was to old for to support "fd-non-iso on".
So is installed the latest package (4.3.0-1ubuntu3) from http://packages.ubuntu.com/xenial/net/iproute2:

$ ip -V
ip utility, iproute2-ss151103

Now it is working. Thanks for you help.

Post Reply