Unable to get adaptor into FD Mode under Linux

CAN FD and LIN Interface for High-Speed USB 2.0
FoobarWizzard
Posts: 6
Joined: Thu 26. Jul 2018, 17:56

Unable to get adaptor into FD Mode under Linux

Post by FoobarWizzard » Thu 26. Jul 2018, 18:59

In short I cannot receive FD frames under Linux using the latest driver when compiled for either chardev or netdev. Note under windows the PCAN-VIEW application works fine. The device to which I am connected has a 500k nominal speed with a 2M data rate for FD frames. I am able to receive frames in PCAN-VIEW under windows using these settings and a clock rate of 80Mhz. However I need to use Linux.

First, starting when compiled for chardev:

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0/test$ cat /sys/class/pcan/version 
8.6.0

fb@xxx:~/Downloads/peak-linux-driver-8.6.0/test$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20180720_n (8.6.0) Jul 26 2018 16:20:05 --------------
*------------- [mod] [isa] [pci] [pec] [dng] [par] [usb] [pcc] --------------
*--------------------- 2 interfaces @ major 243 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   -NA- ffffffff 000 0x001c 00000003 00000000 00000003 00000000 0x0000
33  usbfd   -NA- ffffffff 255 0x001c 00000000 00000000 00000000 00000000 0x0000

fb@xxx:~/Downloads/peak-linux-driver-8.6.0/test$ lspcan -a -i
pcanusbfd32	CAN1	-	80MHz	500k+2M	CLOSED
pcanusbfd33	CAN2	-	80MHz	500k+2M	CLOSED

fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ ls /dev/ | grep pcan
pcan32
pcan33
pcanusbfd32
pcanusbfd33
pcanusbpfd32
pcanusbpfd33
pcan-usb_pro_fd
So at this point I'll try and use pcanfdtst to try and receive some frames from my device. Note it would appear that the -B parameter is not correctly interpreted by the program:

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ pcanfdtst rx -b 500000 -B=2000000 -c 80 --fd /dev/pcanusbfd32 -D
Time base: 1532621538.845629 s.
start opening 1 devices:
opening "/dev/pcanusbfd32" with flags=8a000004h bitrate=500000 bps sample_pt=0 dbitrate=0 bps dsample_pt=0 clock=80 Hz
"/dev/pcanusbfd32" opened (fd=3)
channel features: 0000007dh
tst_fdmax=3
start infinite loop
loop #1 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=1h flags=31000080h len=0 ts=1532621538.902459 s.
handle_rx_tst_status(3)
1532621538~902459 /dev/pcanusbfd32 > BUS_STATE=ACTIVE   [Rx:0 Tx:0]   - 
loop #2 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=2h flags=33000080h len=0 ts=1532621549.067487 s.
handle_rx_tst_status(3)
1532621549.067487 /dev/pcanusbfd32 > BUS_STATE=WARNING  [Rx:96 Tx:0]   - 
loop #3 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=3h flags=33000080h len=0 ts=1532621549.266693 s.
handle_rx_tst_status(3)
1532621549.266693 /dev/pcanusbfd32 > BUS_STATE=PASSIVE  [Rx:128 Tx:0]   - 
loop #4 (max=0)
At this point the LED on the CAN1 interface flashes red on the device and the bus state goes to passive. You can see in the above output that dbrate=0 is not set so I am assuming this is the problem. So I try to experiment with other values of "-B":

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ pcanfdtst rx -b 500000 -B=2M -c 80 --fd /dev/pcanusbfd32 -D
Time base: 1532621755.590994 s.
start opening 1 devices:
opening "/dev/pcanusbfd32" with flags=8a000004h bitrate=500000 bps sample_pt=0 dbitrate=0 bps dsample_pt=0 clock=80 Hz
"/dev/pcanusbfd32" opened (fd=3)
channel features: 0000007dh
tst_fdmax=3
start infinite loop
loop #1 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=1h flags=31000080h len=0 ts=1532621755.640194 s.
handle_rx_tst_status(3)
1532621755~640194 /dev/pcanusbfd32 > BUS_STATE=ACTIVE   [Rx:0 Tx:0]   - 
loop #2 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=2h flags=33000080h len=0 ts=1532621763.091145 s.
handle_rx_tst_status(3)
1532621763.091145 /dev/pcanusbfd32 > BUS_STATE=WARNING  [Rx:96 Tx:0]   - 
loop #3 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=3h flags=33000080h len=0 ts=1532621763.291237 s.
handle_rx_tst_status(3)
1532621763.291237 /dev/pcanusbfd32 > BUS_STATE=PASSIVE  [Rx:128 Tx:0]   - 
loop #4 (max=0)
Interrupted!
end of test loop (tst=0).
"/dev/pcanusbfd32" closed (fd=3)
/dev/pcanusbfd32 > [packets=0 calls=3 bytes=0 seq_err=0]
all 1 devices closed
--- stop logging ---
received frames: 0
fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ pcanfdtst rx -b 500000 -B=2000000 -c 80 --fd /dev/pcanusbfd32 -D
Time base: 1532621838.431304 s.
start opening 1 devices:
opening "/dev/pcanusbfd32" with flags=8a000004h bitrate=500000 bps sample_pt=0 dbitrate=0 bps dsample_pt=0 clock=80 Hz
"/dev/pcanusbfd32" opened (fd=3)
channel features: 0000007dh
tst_fdmax=3
start infinite loop
loop #1 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=1h flags=31000080h len=0 ts=1532621838.479586 s.
handle_rx_tst_status(3)
1532621838~479586 /dev/pcanusbfd32 > BUS_STATE=ACTIVE   [Rx:0 Tx:0]   - 
loop #2 (max=0)
Interrupted!
end of test loop (tst=0).
"/dev/pcanusbfd32" closed (fd=3)
/dev/pcanusbfd32 > [packets=0 calls=3 bytes=0 seq_err=0]
all 1 devices closed
--- stop logging ---
received frames: 0
I cannot seem to get the dbrate value to be set to anything. Please note I also tried specifying the device as "/dev/pcan32" and "/dev/pcanusbpfd32" " So I try the netdev approach:

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ cat /proc/pcan
*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20180720_n (8.6.0) Jul 26 2018 17:53:12 --------------
*---------- [mod] [isa] [pci] [pec] [dng] [par] [usb] [pcc] [net] -----------
*--------------------- 2 interfaces @ major 243 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   can0 ffffffff 000 0x001c 00000000 00000000 00000000 00000000 0x0000
33  usbfd   can1 ffffffff 255 0x001c 00000000 00000000 00000000 00000000 0x0000

fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ sudo ip link set can0 type can bitrate 500000 dbitrate 2000000 fd on
fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ sudo ip link set can0 up
fb@xxx:~/Downloads/peak-linux-driver-8.6.0$ candump can0
At this point I turn on my device while running candump and again the LED on the CAN1 interface flashes red and the bus goes into passive (see error counter below). I am presuming again that the dbrate is not set somehow.

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0cat /proc/pcan

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20180720_n (8.6.0) Jul 26 2018 17:53:12 --------------
*---------- [mod] [isa] [pci] [pec] [dng] [par] [usb] [pcc] [net] -----------
*--------------------- 2 interfaces @ major 243 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32  usbfd   can0 ffffffff 000 0x001c 00000002 00000000 00000002 000104a7 0x000c
33  usbfd   can1 ffffffff 255 0x001c 00000000 00000000 00000000 00000000 0x0000
Any idea what is going wrong or where the problem is?

Thanks.

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Unable to get adaptor into FD Mode under Linux

Post by S.Grosjean » Fri 27. Jul 2018, 09:42

Hi,

Okay. It's actually an issue related to a typo in the inline help of pcanfdtst:

Code: Select all

$ ./pcanfdtst --help

        -B | --brs           data bitrate used for sending CANFD msgs
...
        -d | --dbitrate v    set data bitrate to "v" bps
"-B" option is definitively not the option that enables to setup the data bitrate but the option that enables to set the BRS bit in the outgoing CAN FD frames. To specify the data bitrate, please use the "-d" option instead.

See also the provided user guide in the Documentation directory:
Capture.JPG
Capture.JPG (31.81 KiB) Viewed 12186 times
The inline help of the pcanfdtst will be fixed in the next release. Thanks.

Stéphane
— Stéphane

FoobarWizzard
Posts: 6
Joined: Thu 26. Jul 2018, 17:56

Re: Unable to get adaptor into FD Mode under Linux

Post by FoobarWizzard » Fri 27. Jul 2018, 11:37

Hello,

Now when trying to use the -d parameter the device fails to open with error -33:

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0/Documentation$ sudo pcanfdtst rx --fd -b 500k -d 2M -c 60 /dev/pcanusbfd32 
failed to open "/dev/pcanusbfd32" (err -33)

No pcan device is opened. Exiting application
Note the older incorrect command-line from yesterday will not fail and the device will open so this is a different problem.

Just so you know I actually want to use netdev because all my code uses SocketCAN, I am only trying to get pcanfdtst/chardev to work because I want to confirm I can definitely send/receive FD frames. SO if you know why netdev is not working either, it might be worth troubleshooting that?

In the mean time I will download an older driver and see if that makes any difference.

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Unable to get adaptor into FD Mode under Linux

Post by S.Grosjean » Fri 27. Jul 2018, 11:45

Hi,

The "-c" argument specifies the Clock value "in Hz". So please use "-c 60000000" instead.

Code: Select all

        -c | --clock v       select clock frequency "v" Hz
You can also use "-c 60M" as proposed in the same example from the user documentation:
Capture.JPG
Capture.JPG (31.81 KiB) Viewed 12182 times
Stéphane
— Stéphane

FoobarWizzard
Posts: 6
Joined: Thu 26. Jul 2018, 17:56

Re: Unable to get adaptor into FD Mode under Linux

Post by FoobarWizzard » Fri 27. Jul 2018, 11:49

I should have looked at dmesg as error 33 is a bitrate error, it does not seem to like the nominal bitrate of 500k:

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0/Documentation$ dmesg | tail
[10680.203878] pcan: clk=24 btr=500000 sp=0 [BRP=0 TSEGx=0/0 SJW=0]
[10697.339966] pcan: bitrate error 971.8% too high
[10697.339969] pcan: PCAN-USB Pro FD CAN1: error in user nominal bittimings:
[10697.339971] pcan: clk=24 btr=284 sp=0 [BRP=0 TSEGx=0/0 SJW=0]
[10706.415078] pcan: bitrate error 971.8% too high
[10706.415082] pcan: PCAN-USB Pro FD CAN1: error in user nominal bittimings:
[10706.415084] pcan: clk=24 btr=284 sp=0 [BRP=0 TSEGx=0/0 SJW=0]
[10711.366893] pcan: bitrate error 999.9% too high
[10711.366897] pcan: PCAN-USB Pro FD CAN1: error in user nominal bittimings:
[10711.366898] pcan: clk=24 btr=500000 sp=0 [BRP=0 TSEGx=0/0 SJW=0]

FoobarWizzard
Posts: 6
Joined: Thu 26. Jul 2018, 17:56

Re: Unable to get adaptor into FD Mode under Linux

Post by FoobarWizzard » Fri 27. Jul 2018, 11:54

Sorry I posted in between you giving me the answer. So specifying the clock-rate in Hz works but I still cannot communicate with my device (goes into bus_passive with flashing red LED). Hmm.

Code: Select all

fb@xxx:~/Downloads/peak-linux-driver-8.6.0/Documentation$ sudo pcanfdtst rx --fd -b 500k -d 2M -c 24000000 /dev/pcanusbfd32 -D
Time base: 1532685024.183382 s.
start opening 1 devices:
opening "/dev/pcanusbfd32" with flags=ca000004h bitrate=500000 bps sample_pt=0 dbitrate=2000000 bps dsample_pt=0 clock=24000000 Hz
"/dev/pcanusbfd32" opened (fd=3)
channel features: 0000007dh
tst_fdmax=3
start infinite loop
loop #1 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=1h flags=31000080h len=0 ts=1532685024.234705 s.
handle_rx_tst_status(3)
1532685024~234705 /dev/pcanusbfd32 > BUS_STATE=ACTIVE   [Rx:0 Tx:0]   - 
loop #2 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=2h flags=33000080h len=0 ts=1532685034.990503 s.
handle_rx_tst_status(3)
1532685034.990503 /dev/pcanusbfd32 > BUS_STATE=WARNING  [Rx:96 Tx:0]   - 
loop #3 (max=0)
pcanfd_recv_msg(3) returns 0
Got msg type=3 id=3h flags=33000080h len=0 ts=1532685035.190587 s.
handle_rx_tst_status(3)
1532685035.190587 /dev/pcanusbfd32 > BUS_STATE=PASSIVE  [Rx:128 Tx:0]   - 
loop #4 (max=0)

FoobarWizzard
Posts: 6
Joined: Thu 26. Jul 2018, 17:56

Re: Unable to get adaptor into FD Mode under Linux

Post by FoobarWizzard » Fri 27. Jul 2018, 12:23

I have plugged the device into itself CAN1->CAN2 and I can send and receive CAN-FD frames so there is nothing wrong with the driver. There must be some other odd reason why the device I am communicating with seems to work OK under windows but not Linux.

I would like to try getting the device working under netdev, was there anything incorrect about the way in which I was trying to configure the adaptor using netdev (see commands above) ?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Unable to get adaptor into FD Mode under Linux

Post by PEAK-Support » Fri 27. Jul 2018, 13:16

We do not see if you test on Windows also the fast Bitrate - but keep in mind:

You need to use a terminated cable - also when you have a very short CAN Lane between the two ports
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

User avatar
S.Grosjean
Software Development
Software Development
Posts: 357
Joined: Wed 4. Jul 2012, 17:02

Re: Unable to get adaptor into FD Mode under Linux

Post by S.Grosjean » Fri 27. Jul 2018, 14:01

Hi,

You will be able to use the netdev mode as well, except that this is not possible to specify any other clock than the default one (80 MHz) in that mode.

Stéphane
— Stéphane

FoobarWizzard
Posts: 6
Joined: Thu 26. Jul 2018, 17:56

Re: Unable to get adaptor into FD Mode under Linux

Post by FoobarWizzard » Fri 27. Jul 2018, 14:47

Hello,

I have the device working under netdev now, I was not defining the sample-point which was causing the problem. Entirely my fault. The following works for netdev:

Code: Select all

fb@xxx:~$ sudo ip link set can0 type can bitrate 500000 sample-point 0.800 dbitrate 2000000 dsample-point 0.800 fd on
fb@xxx:~$ sudo ip link set can0 up
However, do you know how to specify a sample-point of 0.800 (as above) when using pcanfdtst? it does not accept floats as a command line parameter.

Thanks.

fb

Post Reply