|
| 1 | +# Socket can is easy to use, but the default devie name is can{idx} and will vary depend on the order the device got connected to the computer. Below is the precedure of setting up persist ID for those socket CAN devices. |
| 2 | + |
| 3 | +## For canable devices, goto https://canable.io/updater/ to flush its firmware to candlelight to use socketcan, YAM comes with pre-flushed candlelight firmware. |
| 4 | + |
| 5 | + |
| 6 | +## Step1: find sysfd paths for can devices |
| 7 | + |
| 8 | +```shell |
| 9 | +$ ls -l /sys/class/net/can* |
| 10 | +``` |
| 11 | + |
| 12 | +this should give you something liks |
| 13 | +```shell |
| 14 | +lrwxrwxrwx 1 root root 0 Jul 15 14:35 /sys/class/net/can0 -> ../../devices/platform/soc/your_can_device/can0 |
| 15 | +lrwxrwxrwx 1 root root 0 Jul 15 14:35 /sys/class/net/can1 -> ../../devices/platform/soc/your_can_device/can1 |
| 16 | +lrwxrwxrwx 1 root root 0 Jul 15 14:35 /sys/class/net/can2 -> ../../devices/platform/soc/your_can_device/can2 |
| 17 | +``` |
| 18 | + |
| 19 | +## Step 2: Use udevadm to Gather Attributes |
| 20 | +```shell |
| 21 | +udevadm info -a -p /sys/class/net/can0 | grep -i serial |
| 22 | +``` |
| 23 | + |
| 24 | +## Step 3: Create udev Rules |
| 25 | +edit `/etc/udev/rules.d/90-can.rules` |
| 26 | +```shell |
| 27 | +sudo vim /etc/udev/rules.d/90-can.rules |
| 28 | +``` |
| 29 | +add |
| 30 | +``` |
| 31 | +SUBSYSTEM=="net", ACTION=="add", ATTRS{serial}=="004E00275548501220373234", NAME="can_follow_l" |
| 32 | +SUBSYSTEM=="net", ACTION=="add", ATTRS{serial}=="0031005F5548501220373234", NAME="can_follow_r" |
| 33 | +``` |
| 34 | + |
| 35 | +IMPORTANT!!!: Name should start with can (for USB-CAN adapter) or en/eth (for EtherCAT-CAN adapter). And the maximum length limit for a CAN interface name is 13 characters. |
| 36 | + |
| 37 | +## Step 4: Reload udev Rules |
| 38 | +```shell |
| 39 | +sudo udevadm control --reload-rules && sudo systemctl restart systemd-udevd && sudo udevadm trigger |
| 40 | +``` |
| 41 | + |
| 42 | +If needed, plug unplug the candevice to make sure the change is effective. |
| 43 | + |
| 44 | +run the following command to set up the can device, and you need to run this command after every reboot. |
| 45 | +``` |
| 46 | +sudo ip link set up can_right type can bitrate 1000000 |
| 47 | +``` |
| 48 | + |
| 49 | +## Step 5: Verify the can device |
| 50 | +```shell |
| 51 | +$ ip link show |
| 52 | +1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 |
| 53 | + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
| 54 | +2: enp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 |
| 55 | + link/ether d8:43:ae:b7:43:0b brd ff:ff:ff:ff:ff:ff |
| 56 | +5: tailscale0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1280 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 500 |
| 57 | + link/none |
| 58 | +6: can_right: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10 |
| 59 | + link/can |
| 60 | +7: can_left: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10 |
| 61 | + link/can |
| 62 | +``` |
| 63 | + |
| 64 | +You can see that this can device got it's name can_right/can_left |
| 65 | + |
0 commit comments