Multiple pcan devices on a Linux system

CAN FD Interface for PCI Express Mini (PCIe)
Post Reply
r_frojd
Posts: 6
Joined: Wed 14. Apr 2021, 09:26

Multiple pcan devices on a Linux system

Post by r_frojd » Wed 14. Apr 2021, 09:58

Hi Forum!
I am using two PCAN-miniPCIe FD and one PCAN-M.2 FD on a UP Xtreme i7C1-8565U and I am now trying to verify and secure that all devices are "fixed" and can´'t change ID on reboot. This is of utmost importance as each channel controls a position on a legged robot.
The system is running Ubuntu 18.04 AND using the PCAN-Driver-Linux.


I would appreciate help how to config this on linux.

Image
Image


best regards
Robin

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

Re: Multiple pcan devices on a Linux system

Post by M.Heidemann » Wed 14. Apr 2021, 12:11

Hello Robin,

You have to set a device-number using the pcan-settings utility, as described starting on page 31 of the PCAN-Linux documentation:
1404_01.jpg.png
1404_01.jpg.png (17.03 KiB) Viewed 14512 times
To set the order of channel assigment please have a look at the assign parameter (described on page 39 of the PCAN-Linux driver documentation) which will change be used to change the default name assignment:
The option is added to:

Code: Select all

/etc/modprobe.d/pcan.conf 
The setting of option in the pcan-conf file is also documented on page 9 -12 -Chapter 3.3 : Configure Software
1404_02.jpg.png
1404_02.jpg.png (36.2 KiB) Viewed 14512 times

make sure to reload the driver afterwards:

Code: Select all

sudo rmmod pcan

Code: Select all

sudo modprobe pcan
The assignment of device IDs to CAN-Channels is also described in this forum post (NetDev -> SocketCAN compatible):

viewtopic.php?f=7&t=1861&p=5423&hilit=devid#p5423

You can use this post as reference.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

r_frojd
Posts: 6
Joined: Wed 14. Apr 2021, 09:26

Re: Multiple pcan devices on a Linux system

Post by r_frojd » Wed 14. Apr 2021, 14:58

Thanks for the prompt reply! :)

The second part I dont think I understand correctly. Even if I am looking on the reference post.

So this is where I am at:
I unplugged all card except one.
I did the steps you mention from the manual.

here is the output for that card:

Code: Select all

robot@robot-UP-WHL01:~$ ls -l /dev/pcan*
lrwxrwxrwx 1 root root     10 apr 14 14:53 /dev/pcan0 -> pcanpcifd0
lrwxrwxrwx 1 root root     10 apr 14 14:53 /dev/pcan1 -> pcanpcifd1
lrwxrwxrwx 1 root root     10 apr 14 14:53 /dev/pcan2 -> pcanpcifd2
lrwxrwxrwx 1 root root     10 apr 14 14:53 /dev/pcan3 -> pcanpcifd3
crw-rw-rw- 1 root root 236, 0 apr 14 14:53 /dev/pcanpcifd0
crw-rw-rw- 1 root root 236, 1 apr 14 14:53 /dev/pcanpcifd1
crw-rw-rw- 1 root root 236, 2 apr 14 14:53 /dev/pcanpcifd2
crw-rw-rw- 1 root root 236, 3 apr 14 14:53 /dev/pcanpcifd3

/dev/pcan-pcie_fd:
totalt 0
drwxr-xr-x 2 root root 120 apr 14 14:53  0
lrwxrwxrwx 1 root root  13 apr 14 14:53 'devid=18' -> ../pcanpcifd0
lrwxrwxrwx 1 root root  13 apr 14 14:53 'devid=19' -> ../pcanpcifd1
lrwxrwxrwx 1 root root  13 apr 14 14:53 'devid=20' -> ../pcanpcifd2
lrwxrwxrwx 1 root root  13 apr 14 14:53 'devid=21' -> ../pcanpcifd3
So what should I do in the to fix the assignment for the current card?

Code: Select all

/etc/modprobe.d/pcan.conf 

Code: Select all

 assign=pcanX:canY


best regards
Robin

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

Re: Multiple pcan devices on a Linux system

Post by M.Heidemann » Wed 14. Apr 2021, 15:19

Pardon me,

i made a mistake and marked the wrong option in my screenshot, Im sorry about this.

please use the

Code: Select all

assign=devid[,peak]
option for this.
1404_04.jpg.png
1404_04.jpg.png (36.24 KiB) Viewed 14505 times

This way the devices will enumarate based on their ID.

Furthermore, the device-id is only set once for each device.

If you set the device-ID differently for each channel, it will just use the topmost set device-id.
This device-id is given to the device, not its channels, the channel will receive a minor number.

The example shown in the forum-thread was assuming two one channel devices.

The minor numbers of channels on a device will not be shuffeled on the same device after reboot.

So, make sure to give unique device ids to your other interfaces and use the
option mentioned above for the assign-parameter.

As mentioned earlier, the minor numbers given to each channels per device will not be changed.

As the devices themselves will enumarte correctly, the individual channels will do so as well.

Please report back to us regarding this.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

r_frojd
Posts: 6
Joined: Wed 14. Apr 2021, 09:26

Re: Multiple pcan devices on a Linux system

Post by r_frojd » Wed 14. Apr 2021, 15:53

So, This is how I configured the boards:
Image

And this is how my

Code: Select all

/etc/modprobe.d/pcan.conf 
looks like: (is this correct?)

Code: Select all

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

And here is the output of two devices connected using

Code: Select all

ls -l /dev/pcan*

Code: Select all

robot@robot-UP-WHL01:~$ ls -l /dev/pcan*
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan0 -> pcanpcifd0
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan1 -> pcanpcifd1
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan2 -> pcanpcifd2
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan3 -> pcanpcifd3
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan4 -> pcanpcifd4
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan5 -> pcanpcifd5
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan6 -> pcanpcifd6
lrwxrwxrwx 1 root root     10 apr 14 15:48 /dev/pcan7 -> pcanpcifd7
crw-rw-rw- 1 root root 236, 0 apr 14 15:48 /dev/pcanpcifd0
crw-rw-rw- 1 root root 236, 1 apr 14 15:48 /dev/pcanpcifd1
crw-rw-rw- 1 root root 236, 2 apr 14 15:48 /dev/pcanpcifd2
crw-rw-rw- 1 root root 236, 3 apr 14 15:48 /dev/pcanpcifd3
crw-rw-rw- 1 root root 236, 4 apr 14 15:48 /dev/pcanpcifd4
crw-rw-rw- 1 root root 236, 5 apr 14 15:48 /dev/pcanpcifd5
crw-rw-rw- 1 root root 236, 6 apr 14 15:48 /dev/pcanpcifd6
crw-rw-rw- 1 root root 236, 7 apr 14 15:48 /dev/pcanpcifd7

/dev/pcan-pcie_fd:
totalt 0
drwxr-xr-x 2 root root 120 apr 14 15:48  0
drwxr-xr-x 2 root root 120 apr 14 15:48  1
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=14' -> ../pcanpcifd0
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=15' -> ../pcanpcifd1
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=16' -> ../pcanpcifd2
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=17' -> ../pcanpcifd3
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=18' -> ../pcanpcifd4
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=19' -> ../pcanpcifd5
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=20' -> ../pcanpcifd6
lrwxrwxrwx 1 root root  13 apr 14 15:48 'devid=21' -> ../pcanpcifd7

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

Re: Multiple pcan devices on a Linux system

Post by M.Heidemann » Wed 14. Apr 2021, 16:22

Hello,

please read my previous post, carefully.

The device-id is set once per device - as in once per hardware-device.

The channels of the device will enumerate accordingly, they will
not be mixed up on the same hardware device.

Subsequent set device ids will be ignored, to prohibit
confusion later on you should only set one device-id per hardware device.

You should set the already set device-ids for each channel accordingly
to one specfic id per hardware device.

For example:

PCAN-Minipciefd #1 = device-id = 01
PCAN-Minipciefd #1 = device-id = 02
PCAN-M.2 = device-id = 03

afterwards reboot or reload the driver using

Code: Select all

sudo rmmod pcan
sudo modprobe pcan
apart from this you configuration seems fine.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

r_frojd
Posts: 6
Joined: Wed 14. Apr 2021, 09:26

Re: Multiple pcan devices on a Linux system

Post by r_frojd » Wed 14. Apr 2021, 21:54

Sorry. I read your previous post carefully, but I am not sure I am follow you on this. :roll:

"You should set the already set device-ids for each channel accordingly
to one specfic id per hardware device."


Do you mean then that I should set the same ID for all /dev/pcanpcifdX which are on each board?

So for example ID: 5 for pcanpcifd0, pcanpcifd1, pcanpcifd2 and pcanpcifd3
PCAN-Minipciefd # 1

Code: Select all

crw-rw-rw- 1 root root 236, 0 apr 14 21:17 /dev/pcanpcifd0
crw-rw-rw- 1 root root 236, 1 apr 14 21:17 /dev/pcanpcifd1
crw-rw-rw- 1 root root 236, 2 apr 14 21:17 /dev/pcanpcifd2
crw-rw-rw- 1 root root 236, 3 apr 14 21:17 /dev/pcanpcifd3
So for example ID: 6 for pcanpcifd4, pcanpcifd5, pcanpcifd6 and pcanpcifd7
PCAN-Minipciefd # 2

Code: Select all

crw-rw-rw- 1 root root 236, 0 apr 14 21:17 /dev/pcanpcifd4
crw-rw-rw- 1 root root 236, 1 apr 14 21:17 /dev/pcanpcifd5
crw-rw-rw- 1 root root 236, 2 apr 14 21:17 /dev/pcanpcifd6
crw-rw-rw- 1 root root 236, 3 apr 14 21:17 /dev/pcanpcifd7
So for example ID: 7 for pcanpcifd8, pcanpcifd9, pcanpcifd10 and pcanpcifd11
PCAN-M.2

Code: Select all

crw-rw-rw- 1 root root 236, 0 apr 14 21:17 /dev/pcanpcifd8
crw-rw-rw- 1 root root 236, 1 apr 14 21:17 /dev/pcanpcifd9
crw-rw-rw- 1 root root 236, 2 apr 14 21:17 /dev/pcanpcifd10
crw-rw-rw- 1 root root 236, 3 apr 14 21:17 /dev/pcanpcifd11


Also, if I add

Code: Select all

options pcan assign=devid,peak
to

Code: Select all

/etc/modprobe.d/pcan.conf 
and then use

Code: Select all

dmesg | grep pcan
I can see

Code: Select all

[ 2008.487989] pcan: unknown parameter 'assign' ignored
according to the manual this parameter is only used when netdev interface is selected. Which is not that case here

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

Re: Multiple pcan devices on a Linux system

Post by M.Heidemann » Thu 15. Apr 2021, 11:46

Hello,

You are right, i had it wrong.

I have talked to our Linux-Development team and there was a misconception on my end
on how this is handled on CharDev, i am really sorry.

The device-id is given per channel, not device. The Linux driver does handle this differently
than the Windows driver does, you channel assigment was correct.

Please disregard what i said regarding the device-ids, i mixed things up.

The assign-parameter is not used with the CharDev-driver as the Udev rules will create
additional symbolic links for each device (channel) based on the device ID. For example
if the device-id for a channels was set to 1 this link will be created, which will
be a reference to the channel given this device-ID:

Code: Select all

/dev/pcan-pcie_fd/devid\=1
So after setting the device-id and loading the driver you can access the
device with your application using this link for each channel with the corresponding devid.

This also mentioned in the PCAN-Linux driver documentation on page 16:

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

You can test this by using the channel with for example receivetest:

Code: Select all

 receivetest -f=/dev/pcan-pcie_fd/devid\=1
Please excuse the misconception on my end.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

r_frojd
Posts: 6
Joined: Wed 14. Apr 2021, 09:26

Re: Multiple pcan devices on a Linux system

Post by r_frojd » Thu 15. Apr 2021, 15:14

No worries! All good! I figured it out myself late last night :)

So this how I set it up:
Image

And calling each joint with

Code: Select all

#define DEVICE "/dev/pcan-pcie_fd/devid=X
Did some basic testing with one motor and confirmed it worked as wished!


BTW: You should really check and fix the python lib when runnning CAN-FD. We are a few users that have tried it and can confirm this is not working.
But something is wrong with python lib when trying to InitializeFD. When Initialize without FD it works ok.

C++ is working great.




Thanks! :)

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

Re: Multiple pcan devices on a Linux system

Post by M.Heidemann » Thu 15. Apr 2021, 16:50

Hello,

Please check if you are using python 3.x, if you have prefixed the bitratestring with 'b', as byte literals
in python3 have to be prefixed, this was not necessary in python 2.x:

Examples

Python 2.x

Code: Select all

result = objPCAN.InitializeFD(PCAN_PCIBUS1 , "f_clock=80000000, nom_brp=2, nom_tseg1=63, nom_tseg2=16, nom_sjw=16, data_brp=2, data_tseg1=15, data_tseg2=4, data_sjw=4")
Python 3.x

Code: Select all

result = objPCAN.InitializeFD(PCAN_PCIBUS1, b"f_clock=80000000, nom_brp=2, nom_tseg1=63, nom_tseg2=16, nom_sjw=16, data_brp=2, data_tseg1=15, data_tseg2=4, data_sjw=4")

Please report back to us, if this was indeed the cause for this issue.

Best Regards

Marvin
---
Marvin Heidemann
PEAK-Support Team

Post Reply