Configure CAN AGX Orin - MacRover/maxwell GitHub Wiki
Enable kernel modules
-
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. -
Create a new file to automatically load the
can
andcan_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
-
Run
sudo lsmod | grep can
again. You should seemttcan
,can
, andcan_raw
modules have been loaded.
Configuring JetsonIO pinout
-
Run the following program to configure the GPIO header
sudo /opt/nvidia/jetson-io/jetson-io.py
-
Select
Configure Jetson 40-pin header
-
Select
Configure header pins manually
-
Enable
can0
andcan1
. Then goBack
. -
Select
Save pin changes
. -
Select
Save and reboot to reconfigure pins
. -
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
-
Create the systemd network interface configuration file
sudo nano /etc/systemd/network/80-can.network
-
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
-
Enable systemd-networkd
sudo systemctl enable systemd-networkd
-
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
andcan1
. The state should be indicated bystate UP
orstate 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
- If your CAN device is already in the UP state, bring the device DOWN.
sudo ip link set down can0
- Change the device config to enable loopback
sudo ip link set can0 type can bitrate 500000 loopback on
- Re-enable the CAN interface
sudo ip link set up can0
- If your CAN device is already in the UP state, bring the device DOWN.
-
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://www.cyberciti.biz/faq/linux-how-to-load-a-kernel-module-automatically-at-boot-time/
https://github.com/linux-can/can-utils/issues/68#issuecomment-584505426