Configure CAN AGX Orin - MacRover/maxwell GitHub Wiki

Enable kernel modules

  1. Run sudo lsmod | grep can. You should see the mttcan module is loaded. If you do not see this module, check the files in /etc/modprobe.d/ for a blacklist rule preventing it from loading.

  2. Create a new file to automatically load the can and can_raw modules on boot.

    sudo nano /etc/modules-load.d/can.conf
    

    Copy the following into this file, save, and then reboot.

    # Load can and can_raw modules
    can
    can-raw
    
  3. Run sudo lsmod | grep can again. You should see mttcan, can, and can_raw modules have been loaded.

Configuring JetsonIO pinout

  1. Run the following program to configure the GPIO header

    sudo /opt/nvidia/jetson-io/jetson-io.py
    
  2. Select Configure Jetson 40-pin header

  3. Select Configure header pins manually

  4. Enable can0 and can1. Then go Back.

  5. Select Save pin changes.

  6. Select Save and reboot to reconfigure pins.

  7. After reboot, run sudo /opt/nvidia/jetson-io/jetson-io.py again to confirm the new pin layout. You should see the can related data pins appear on the map of the GPIO header.

Configure network devices

Setup devices

To bring a socketCAN device online (can0 in this example), you need to run the following commands:

sudo ip link set can0 type can bitrate 1000000 sample-point 0.889 prop-seg 0 phase-seg1 15 phase-seg2 2 sjw 2
sudo ip link set up can0

Automatically configure devices at boot

These instructions will bring all can devices online at boot

  1. Create the systemd network interface configuration file

    sudo nano /etc/systemd/network/80-can.network
    
  2. Copy in the following to the file and save.

    [Match]
    Name=can*
    
    [CAN]
    SamplePoint=88.9
    BitRate=1000000
    PropagationSegment=0
    PhaseBufferSegment1=15
    PhaseBufferSegment2=2
    SyncJumpWidth=2
    
  3. Enable systemd-networkd

    sudo systemctl enable systemd-networkd
    
  4. Reboot the computer. The interface should appear in the UP state after boot.

Troubleshooting and testing

  • To view available network interface devices, run the following:

    ip a
    

    You should see your can devices as can0 and can1. The state should be indicated by state UP or state DOWN

  • To test CAN functionality, you can enable loopback. This will echo any data transmitted on a CAN device back to itself.

  • To enable loopback, do the following

    1. If your CAN device is already in the UP state, bring the device DOWN.
      sudo ip link set down can0
      
    2. Change the device config to enable loopback
      sudo ip link set can0 type can bitrate 500000 loopback on
      
    3. Re-enable the CAN interface
      sudo ip link set up can0
      
  • To test transmit/receive, use the can-utils package. You should see the packet twice (once transmitting and once receiving). It is helpful to have two terminal windows open for this test.

    candump can0
    
    cansend can0 123#abcdabcd
    
  • To query a network device, run the following

    ip -details -statistics link show can0
    

References

Use the latest available Jetson Developer Guide: https://docs.nvidia.com/jetson/

https://docs.nvidia.com/jetson/archives/r36.2/DeveloperGuide/HR/ControllerAreaNetworkCan.html

https://docs.nvidia.com/jetson/archives/r36.2/DeveloperGuide/HR/ConfiguringTheJetsonExpansionHeaders.html#hr-configuringthejetsonexpansionheaders

https://www.cyberciti.biz/faq/linux-how-to-load-a-kernel-module-automatically-at-boot-time/

https://askubuntu.com/questions/439613/automatically-bring-up-socketcan-network-interfaces-on-boot-can0

https://github.com/linux-can/can-utils/issues/68#issuecomment-584505426

https://www.freedesktop.org/software/systemd/man/latest/systemd.network.html#[CAN]%20Section%20Options

https://www.kernel.org/doc/Documentation/networking/can.txt