PCAN-miniPCIe with SocketCAN

This forum covers PCAN-Linux and Linux development issues concerning our products
MarcusAA
Posts: 5
Joined: Tue 19. Nov 2019, 16:45

PCAN-miniPCIe with SocketCAN

Post by MarcusAA » Tue 19. Nov 2019, 17:14

I am attempting to use a PCAN-miniPCIe on my PC using SocketCAN. The basic test I have setup is to read and write a message on the CAN bus using the following command:

Code: Select all

cansend can0 123#1122334455667788
and

Code: Select all

candump can0
I have verified that the HW is correctly setup by probing the signal and using a Kvaser dongle.
I have also used an external CAN node to generate a message which I can not detect using the PEAK unit.

For reading in the forum I have seen that the necessary drivers should already be provided by the Kernel. I have also made sure to setup the correct baud rate before the test.

Below is my config:

Code: Select all

uname -a
Linux bum-mxcs 5.0.0-32-generic #34~18.04.2-Ubuntu SMP Thu Oct 10 10:36:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Code: Select all

cat /proc/pcan
cat: /proc/pcan: No such file or directory

Code: Select all

ip link list
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UP mode DEFAULT group default qlen 10
    link/can 
7: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UP mode DEFAULT group default qlen 10
    link/can 
8: can2: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UP mode DEFAULT group default qlen 10
    link/can 
can2 is the Kvaser dongle

Code: Select all

ip -details -statistics link show can0
6: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 250000 sample-point 0.875 
	  tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  sja1000: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       1       0       0  
What could I bee missing?
Many thanks!

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-miniPCIe with SocketCAN

Post by M.Heidemann » Wed 20. Nov 2019, 09:35

Hello,


In your case using:

Code: Select all

cat /proc/pcan/
does not apply, this is only related to manually installed drivers.

Can you send us your:

Code: Select all

ip link set can0 up
command you have used to configure the device?


Additionally we would be interested in seeing the output of:

Code: Select all

ip -details -statistics link show can2

It's possible that the other device has an internal termination.

Check if you have the proper termination on your CAN-bus, our devices are not terminated internally by default.

Try the same procedure with a terminated cable for example and see if it works then.



Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

MarcusAA
Posts: 5
Joined: Tue 19. Nov 2019, 16:45

Re: PCAN-miniPCIe with SocketCAN

Post by MarcusAA » Wed 20. Nov 2019, 12:57

Hi and thanks for your answer.
Question: command you have used to configure the device?
I have done no configuration at all. was not aware that I need to change anything...

Code: Select all

ip link set can1 up
RTNETLINK answers: Operation not permitted
This error on the other hand is not persistent, when I use the same command but on can0 i dont get it.

Code: Select all

PC@bum-mxcs:~$ sudo ip link set can0 up
PC@bum-mxcs:~$ sudo ip link set can1 up
RTNETLINK answers: Invalid argument
Furthermore, when I use it on can2 i get no error.

Code: Select all

ip -details -statistics link show can2
8: can2: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc fq_codel state UP mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE restart-ms 0 
	  bitrate 250000 sample-point 0.875 
	  tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  kvaser_usb: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          980        0          0          1          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    7865       984      980     1       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    48         6        0       0       0       0   
I have properly terminated my CAN bus at both ends ends, the network at them moment only has 2 nodes and is 0.5m long. I have also probed and made sure that the CAN signal is present on the PEAK miniPCI card so it is not a connection issue.
Regards
Marcus

M.Heidemann
Sales & Support
Sales & Support
Posts: 1083
Joined: Fri 20. Sep 2019, 13:31

Re: PCAN-miniPCIe with SocketCAN

Post by M.Heidemann » Wed 20. Nov 2019, 13:51

Hello Marcus,

Your command is missing arguments,
you should bring the devices up like this, for example:

Code: Select all

sudo ip link set can0 up type can bitrate 250000

If you search for "can.txt" on Google you will find the documentation for SocketCAN.

Chapter 6.5.1 will have detailed information about how to set the device properties correctly.


Please ensure that both adaptors have the same configuration.

Set the properties of both your devices correctly and try again.


Best regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

MarcusAA
Posts: 5
Joined: Tue 19. Nov 2019, 16:45

Re: PCAN-miniPCIe with SocketCAN

Post by MarcusAA » Thu 21. Nov 2019, 14:34

Hi,
thanks for the clarification of how to set it up properly.
But, all the CAN modules are setup the same way and even if I use the provided command from your earlier post I can not read or send anything on can0 and can1.

I have no problem using:

Code: Select all

cansend can2 123#1122334455667788
which increase the "RX: bytes" count. In this test I simply connect a 120Ohm between CAN-h and CAN-L using an DSUB adapter. When I do the same command for can0 and can1, the "RX: bytes" count remains at 0.

One issue I can see is that the PEAK unit never leaves the CAN state ERROR-ACTIVE.
When I short CAN-H and CAN-L on can2, the Kvaser dongle, it changes state to BUS-OFF
When I do the same test on the PEAK unit it remains in ERROR-ACTIVE.

Are there and PEAK specific configurations I have to change to make it work?
Regards,
Marcus

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

Re: PCAN-miniPCIe with SocketCAN

Post by M.Maidhof » Thu 21. Nov 2019, 15:35

Hi,

please check your CAN cable connections from the PCAN-miniPCIe card to the D-Sub connectors. With a short between CAN-H and CAN-L the card should state a busoff when you send some frames.

As a test please install our peak-linux-driver-8.9.3 with the netdev option: make NET=NETDEV_SUPPORT

Then please install the driver and make the same tests again.

If the problem still occur, do the following steps to enable MSI instead of INTA on the card.

- Edit /etc/modprobe.d/pcan.conf

# pcan - automatic made entry, begin --------
# if required add options and remove comment
# options pcan type=isa,sp
options pcan usemsi=1
install pcan modprobe --ignore-install pcan
# pcan - automatic made entry, end ----------

2 - unload then reload the driver:

$ sudo rmmod pcan
$ sudo modprobe pcan

do your tests again.

best regards

Michael

MarcusAA
Posts: 5
Joined: Tue 19. Nov 2019, 16:45

Re: PCAN-miniPCIe with SocketCAN

Post by MarcusAA » Fri 22. Nov 2019, 13:18

Hi,
I am getting a bit closer to success now. This is what I have done.

1. Had to perform the following updated in order to successfully perform the command 'make NET=NETDEV_SUPPORT'

Code: Select all

sudo apt-get install build-essential
sudp apt-get install linux-headers- 'uname -r'
2. Got an error 'fatal error: popt.h: No such file or directory'. That was solved by this:

Code: Select all

sudo apt-get install libelf-dev
sudo apt-get install libpopt-dev
3. Making sure the new driver is installed:

Code: Select all

$ cat /proc/pcan

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20191029_n (8.9.3) Nov 22 2019 09:04:33 --------------
*---------- [mod] [isa] [pci] [pec] [dng] [par] [usb] [pcc] [net] -----------
*--------------------- 2 interfaces @ major 240 found -----------------------
*n -type- -ndev- --base-- irq --btr- --read-- --write- --irqs-- -errors- status
 0    pci   can0 fb700000 016 0x011c 00000000 0000015d 00000000 00000000 0x0000
 1    pci   can1 fb700400 016 0x011c 00000000 000004e2 00000000 00000000 0x0000
4. I then tested it with candump and cansend, which worked.

The remanding issue I have now is that I cant receive any messages. As you can see from the above output and when I look at the 'ip -details -statistics link show can0' I am not seeing and RX messages.

Code: Select all

ip -details -statistics link show can0
6: can0: <NOARP> mtu 16 qdisc fq_codel state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state STOPPED restart-ms 100 
	  bitrate 250000 sample-point 0.875 
	  tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  pcan: tseg1 1..16 tseg2 1..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000
	  re-started bus-errors arbit-lost error-warn error-pass bus-off
	  0          0          0          0          0          0         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    809        287      0       0       0       0  
What could be the reason for that?
I did restart the PC and run the following code:

Code: Select all

for c in /sys/class/net/can0/statistics/*; do echo -n "'basename $c': "; cat /$c; done
'basename /sys/class/net/can0/statistics/collisions': 0
'basename /sys/class/net/can0/statistics/multicast': 0
'basename /sys/class/net/can0/statistics/rx_bytes': 0
'basename /sys/class/net/can0/statistics/rx_compressed': 0
'basename /sys/class/net/can0/statistics/rx_crc_errors': 0
'basename /sys/class/net/can0/statistics/rx_dropped': 0
'basename /sys/class/net/can0/statistics/rx_errors': 0
'basename /sys/class/net/can0/statistics/rx_fifo_errors': 0
'basename /sys/class/net/can0/statistics/rx_frame_errors': 0
'basename /sys/class/net/can0/statistics/rx_length_errors': 0
'basename /sys/class/net/can0/statistics/rx_missed_errors': 0
'basename /sys/class/net/can0/statistics/rx_nohandler': 0
'basename /sys/class/net/can0/statistics/rx_over_errors': 0
'basename /sys/class/net/can0/statistics/rx_packets': 0
'basename /sys/class/net/can0/statistics/tx_aborted_errors': 0
'basename /sys/class/net/can0/statistics/tx_bytes': 809
'basename /sys/class/net/can0/statistics/tx_carrier_errors': 0
'basename /sys/class/net/can0/statistics/tx_compressed': 0
'basename /sys/class/net/can0/statistics/tx_dropped': 0
'basename /sys/class/net/can0/statistics/tx_errors': 0
'basename /sys/class/net/can0/statistics/tx_fifo_errors': 0
'basename /sys/class/net/can0/statistics/tx_heartbeat_errors': 0
'basename /sys/class/net/can0/statistics/tx_packets': 287
'basename /sys/class/net/can0/statistics/tx_window_errors': 0
Regards,
Marcus

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

Re: PCAN-miniPCIe with SocketCAN

Post by M.Maidhof » Fri 22. Nov 2019, 14:54

Hi,

did you test with usemsi option? You say candump is working, so you should have received messages, right?

regards

Michael

MarcusAA
Posts: 5
Joined: Tue 19. Nov 2019, 16:45

Re: PCAN-miniPCIe with SocketCAN

Post by MarcusAA » Mon 25. Nov 2019, 08:21

Hi,
I added the usemsi option and restarted the computer and now I can both send and receive messages.
Without taking up to much time I would like to know the following for future projects with the miniPCIe CAN module.

1. Why did the defaulter CAN drivers not work with the miniPCIe module?
2. Why did only the Tx part work when installing the PCAN?
3. Why dose the usemsi option mean? and why dose it allow Rx messages when enabled?
Regards,
Marcus

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

Re: PCAN-miniPCIe with SocketCAN

Post by M.Maidhof » Mon 25. Nov 2019, 11:04

Hi,

good to hear that it is working with msi now. So the problem is related to the interrupt management on your board or BIOS. It looks like INTA is not supported on your miniPCIe slot, and that is why the workaround with msi solves the problem. Here the answers to your questions:

1. default SocketCAN driver from the kernel uses INTA only, which seems not to work on your system.
2. An IRQ is necessary to receive CAN frames, for TX the IRQ will be used to get the TX ok status. So even without a valid IRQ feedback, TX is possible in that case for a single TX frame.
3. see above, this looks like an interupt problem in your specific board or BIOS version.

regards

Michael

Locked