SocketCAN device mapping to hardware CAN port
-
- Posts: 4
- Joined: Tue 17. Nov 2020, 11:38
SocketCAN device mapping to hardware CAN port
Hi,
until now i had a single PCI Express Peak CAN device which i use with the kernel main line driver and SocketCan. This works pretty smooth!
Now we add another physically separated CAN bus which results either in two PCI Express CAN cards or in one PCI Express CAN card with two ports.
How can i now ensure that a certain SocketCAN network device (e.g. can0) is consitently mapped to the same hardware CAN port?
cheers,
Bernhard
until now i had a single PCI Express Peak CAN device which i use with the kernel main line driver and SocketCan. This works pretty smooth!
Now we add another physically separated CAN bus which results either in two PCI Express CAN cards or in one PCI Express CAN card with two ports.
How can i now ensure that a certain SocketCAN network device (e.g. can0) is consitently mapped to the same hardware CAN port?
cheers,
Bernhard
Re: SocketCAN device mapping to hardware CAN port
Hi,
when using the main line kernel driver with two different cards, it is not safe that the SocketCAN network device is consistently mapped to the same hardware port. In that case the use of the peak-linux-driver in Netdev mode and using the assign parameter to fix the devices to a given device number of the card will be an option. See manual of the peak-linux-driver for more details:
http://www.peak-system.com/fileadmin/me ... an_eng.pdf
AFAIK using a two channel card with the main line kernel driver should also work without mixing canX devices during different bootups.
regards
Michael
when using the main line kernel driver with two different cards, it is not safe that the SocketCAN network device is consistently mapped to the same hardware port. In that case the use of the peak-linux-driver in Netdev mode and using the assign parameter to fix the devices to a given device number of the card will be an option. See manual of the peak-linux-driver for more details:
http://www.peak-system.com/fileadmin/me ... an_eng.pdf
AFAIK using a two channel card with the main line kernel driver should also work without mixing canX devices during different bootups.
regards
Michael
-
- Posts: 4
- Joined: Tue 17. Nov 2020, 11:38
Re: SocketCAN device mapping to hardware CAN port
Hi,
some more questions came up regarding your answer:
Regarding two different cards:
* show pci bus mappings for peak adapter:
* show network device mapping to pci bus id:
----
Regarding mainline driver/netdev-mode:
PCAN-Driver-Linux_UserMan_eng 4.8 sounds like i can use the peak-linux-driver in netdev mode as a drop-in for the mainline driver with SocketCAN. Is this true?
PCAN-Driver-Linux_UserMan_eng 4.8 mentions:
If this is answered in PCAN-Driver-Linux_UserMan_eng 4.8, i will read it some more
Thx, Bernhard
some more questions came up regarding your answer:
Regarding two different cards:
Would checking the PCI bus mappings and having according Udev rules help?when using the main line kernel driver with two different cards, it is not safe that the SocketCAN network device is consistently mapped to the same hardware port.
* show pci bus mappings for peak adapter:
Code: Select all
lspci | grep -ni peak
Code: Select all
ls -la /sys/class/net/
Code: Select all
ls -la /sys/class/net/ | grep can
Regarding mainline driver/netdev-mode:
Our application is build around using SocketCAN. So we would like to continue using this.In that case the use of the peak-linux-driver in Netdev mode and using the assign parameter to fix the devices to a given device number of the card will be an option
PCAN-Driver-Linux_UserMan_eng 4.8 sounds like i can use the peak-linux-driver in netdev mode as a drop-in for the mainline driver with SocketCAN. Is this true?
PCAN-Driver-Linux_UserMan_eng 4.8 mentions:
Is there a way to use the "assign parameter" you mentioned via the mainline kernel as well?Since kernel version 3.6, the netdev interface with all of the PEAK-System PC CAN interfaces is natively included in the mainline kernel. So, there is no need to install the PCAN driver for Linux when planning to use the SocketCAN interface in applications.
If this is answered in PCAN-Driver-Linux_UserMan_eng 4.8, i will read it some more

Thx, Bernhard
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: SocketCAN device mapping to hardware CAN port
Hello,
We would recommend to use either a two channel card, as
it will not reiterate devices to our knowledge or to use the NetDev-variant of our PCAN-Linux driver.
We don't know if your proposed solution could worked, as we have not tested this and cannot conclusively answer this.
Yes, the PCAN-Linux driver built in NetDev mode is a defacto stand-in for the mainline-driver with additonal features, such as the assign-parameter, hence why my colleague Michael suggested this as a solution.
The assign-parameter is described in detail in chapter 4.8 of the PCAN-Linux driver documentation:
http://www.peak-system.com/fileadmin/me ... an_eng.pdf
For the assign-parameter to work a device-id has to be set, the following forum thread showcases this:
viewtopic.php?f=7&t=1861&p=5423&hilit=devid#p5423
Here a little example using the pcan-settings utility:
Make sure you use the assign paramter for every available channel, the channels come up as, for example, pcanpci32 -33 (using „cat /proc/pcan“):
You can check the current device ID like this (from the driver directory):
sudo test/pcan-settings -f=/dev/pcanpci32 -d
The next step would be assigning a DeviceID to each device (from the driver directory):
sudo test/pcan-settings -f=/dev/pcanpci32 -d=0
sudo test/pcan-settings -f=/dev/pcanpci33 -d=1
etc ..
Afterwards just add the line:
options pcan assign=devid
in /etc/modprobe.d/pcan.conf with your text-editor,
like it is described in the forum post.
On next startup the channels will be assigned to the device ID you have set before.
For further questions, feel free to conact me again.
Best Regards
Marvin
We would recommend to use either a two channel card, as
it will not reiterate devices to our knowledge or to use the NetDev-variant of our PCAN-Linux driver.
We don't know if your proposed solution could worked, as we have not tested this and cannot conclusively answer this.
Yes, the PCAN-Linux driver built in NetDev mode is a defacto stand-in for the mainline-driver with additonal features, such as the assign-parameter, hence why my colleague Michael suggested this as a solution.
The assign-parameter is described in detail in chapter 4.8 of the PCAN-Linux driver documentation:
http://www.peak-system.com/fileadmin/me ... an_eng.pdf
For the assign-parameter to work a device-id has to be set, the following forum thread showcases this:
viewtopic.php?f=7&t=1861&p=5423&hilit=devid#p5423
Here a little example using the pcan-settings utility:
Make sure you use the assign paramter for every available channel, the channels come up as, for example, pcanpci32 -33 (using „cat /proc/pcan“):
You can check the current device ID like this (from the driver directory):
sudo test/pcan-settings -f=/dev/pcanpci32 -d
The next step would be assigning a DeviceID to each device (from the driver directory):
sudo test/pcan-settings -f=/dev/pcanpci32 -d=0
sudo test/pcan-settings -f=/dev/pcanpci33 -d=1
etc ..
Afterwards just add the line:
options pcan assign=devid
in /etc/modprobe.d/pcan.conf with your text-editor,
like it is described in the forum post.
On next startup the channels will be assigned to the device ID you have set before.
For further questions, feel free to conact me again.
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
-
- Posts: 4
- Joined: Tue 17. Nov 2020, 11:38
Re: SocketCAN device mapping to hardware CAN port
hi,
Sorry for my slow comprehension
---
So to conclude:
As our preferred option is to use a two-channel Peak PCI CAN card, we can continue to use the main-line kernel driver, and should not expect any mixing of the mapping.
Thanks for your support!
Bernhard
Sorry for my slow comprehension

- in case of two seperate Peak PCI CAN cards
- we should use the PCAN-Linux driver in NetDev mode, and use the assign-parameter by setting the device-id for the single-channel cards as we need them.
- in case of a two channel Peak PCI CAN card, we have two options:
- we can use the PCAN-Linux driver in NetDev mode and use the assign-parameter by setting the device-id for the single-channel cards as we need them.
- we continue using the main-line kernel driver, and the channels should not mix the canX mapping per boot.
---
So to conclude:
As our preferred option is to use a two-channel Peak PCI CAN card, we can continue to use the main-line kernel driver, and should not expect any mixing of the mapping.
Thanks for your support!
Bernhard
-
- Sales & Support
- Posts: 1083
- Joined: Fri 20. Sep 2019, 13:31
Re: SocketCAN device mapping to hardware CAN port
Hello,
Yes, to our knowledge this is the easiest approach and the channel should not be mixed up on the same device.
You still can use the proprietary PCAN-Linux driver and the "assign-parameter" for the unlikely case that an issue does arise with this solution.
Either solution will support the use of SocketCAN.
Best Regards
Marvin
Yes, to our knowledge this is the easiest approach and the channel should not be mixed up on the same device.
You still can use the proprietary PCAN-Linux driver and the "assign-parameter" for the unlikely case that an issue does arise with this solution.
Either solution will support the use of SocketCAN.
Best Regards
Marvin
---
Marvin Heidemann
PEAK-Support Team
Marvin Heidemann
PEAK-Support Team
-
- Posts: 4
- Joined: Tue 17. Nov 2020, 11:38
Re: SocketCAN device mapping to hardware CAN port
Perfect!
Awesome support, thanks for your help!
Bernhard
Awesome support, thanks for your help!
Bernhard