This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] AM69: How can I assign interface ID to CAN modules

Part Number: AM69

I want to use the CAN interfaces can0, can1, can2 and can3 from Linux user space and hence want hardcode the IDs.

Currently based on the probe sequence from the Kernel, these get assigned randomly.

I tried using aliases in the Kernel Device Tree, but this doesn't help.

        aliases {                                                               
                can0 = &main_mcan16;                                            
                can1 = &mcu_mcan0;                                              
                can2 = &mcu_mcan1;                                              
                can6 = &main_mcan6;                                             
                can7 = &main_mcan7;
        };

  • If "aliases" in the Linux Device Tree are not working, the other option is to modify the udev rules and add your own for CANs.

    Please do the below steps.

    1. Add a new udev rule for CAN in /etc/udev/rules.d/11-can-mylocal.rules

    #11-can-mylocal.rules
    
    KERNELS=="40528000.can", ACTION=="add", NAME="can1"
    KERNELS=="40568000.can", ACTION=="add", NAME="can0"
    KERNELS=="2771000.can", ACTION=="add", NAME="can6"
    KERNELS=="2761000.can", ACTION=="add", NAME="can7"

    2. Reload udev rules

    udevadm control --reload-rules

    3. Reboot

    4. After the reboot, check the interfaces.

    root@am69-sk:~# ls -la /sys/class/net/can*/device
    lrwxrwxrwx 1 root root 0 Sep  5 08:32 /sys/class/net/can0/device -> ../../../40528000.can
    lrwxrwxrwx 1 root root 0 Sep  5 08:32 /sys/class/net/can1/device -> ../../../40568000.can
    lrwxrwxrwx 1 root root 0 Sep  5 08:32 /sys/class/net/can6/device -> ../../../2771000.can
    lrwxrwxrwx 1 root root 0 Sep  5 08:32 /sys/class/net/can7/device -> ../../../2761000.can

    Regards

    Karan