Jetson AGX - CAN Interface

Hello,

I am trying to make the JETSON AGX work with the CAN interfaces :
• CAN0 : RX 29 and TX 31
• CAN1 : RX 37 and TX 33

I am using a transceiver CAN MCP2551 (powered on 5V from JETSON Pin 2 or 4). The transceiver has a resistor of 120 ohms between the CAN_L and CAN_H, so hardware wise we are okay.

The protocol is 500kb/s, so High Speed CAN. However the CAN always comes up with an error on the JETSON, the same program runs perfectly well on other systems. I cannot communicate with other systems (CANUSB and Beaglebone also with a MCP2551). I have seen a tremendous amoutn of questions regrading this topic. However without any success… I have tried many manipulations :

Manipultion 1:

  1. Install Kernel Drivers
    Modprobe can
    Modprobe can-dev
    Modprobe can-raw
    Modprobe mttcan

  2. Configure JETSON
    Options A) use script :
    Sudo /opt/nvidia/jetson-io/jetson-io.py

I configure the device tree for can0 et can1. After reboot I check the pinmux :
Sudo su
Cat /sys/kernel/debug/tegra_pinctrl_reg | grep can

Bank: 1 Reg: 0x0c303000 Val: 0x0000c400 → can1_dout_paa0
Bank: 1 Reg: 0x0c303008 Val: 0x0000c454 → can1_din_paa1
Bank: 1 Reg: 0x0c303010 Val: 0x0000c400 → can0_dout_paa2
Bank: 1 Reg: 0x0c303018 Val: 0x0000c454 → can0_din_paa3
Bank: 1 Reg: 0x0c303020 Val: 0x0000c000 → can0_stb_paa4
Bank: 1 Reg: 0x0c303028 Val: 0x0000c000 → can0_en_paa5
Bank: 1 Reg: 0x0c303030 Val: 0x0000c058 → can0_wake_paa6
Bank: 1 Reg: 0x0c303038 Val: 0x0000c048 → can0_err_paa7
Bank: 1 Reg: 0x0c303040 Val: 0x0000c054 → can1_stb_pbb0
Bank: 1 Reg: 0x0c303048 Val: 0x0000c054 → can1_en_pbb1
Bank: 1 Reg: 0x0c303050 Val: 0x0000c058 → can1_wake_pbb2
Bank: 1 Reg: 0x0c303058 Val: 0x0000c414 → can1_err_pbb3

Options B) Use busybox memdev
sudo busybox devmem 0x0c303000 32 0x0000C400
sudo busybox devmem 0x0c303008 32 0x0000C458
sudo busybox devmem 0x0c303010 32 0x0000C400
sudo busybox devmem 0x0c303018 32 0x0000C458

After reboot, again pinmux :
Sudo su
Cat /sys/kernel/debug/tegra_pinctrl_reg | grep can

Bank: 1 Reg: 0x0c303000 Val: 0x0000c400 → can1_dout_paa0
Bank: 1 Reg: 0x0c303008 Val: 0x0000c458 → can1_din_paa1
Bank: 1 Reg: 0x0c303010 Val: 0x0000c400 → can0_dout_paa2
Bank: 1 Reg: 0x0c303018 Val: 0x0000c458 → can0_din_paa3
Bank: 1 Reg: 0x0c303020 Val: 0x0000c000 → can0_stb_paa4
Bank: 1 Reg: 0x0c303028 Val: 0x0000c000 → can0_en_paa5
Bank: 1 Reg: 0x0c303030 Val: 0x0000c058 → can0_wake_paa6
Bank: 1 Reg: 0x0c303038 Val: 0x0000c048 → can0_err_paa7
Bank: 1 Reg: 0x0c303040 Val: 0x0000c054 → can1_stb_pbb0
Bank: 1 Reg: 0x0c303048 Val: 0x0000c054 → can1_en_pbb1
Bank: 1 Reg: 0x0c303050 Val: 0x0000c058 → can1_wake_pbb2
Bank: 1 Reg: 0x0c303058 Val: 0x0000c414 → can1_err_pbb3

Q) Between A et B, which is the recommend method ? And why do we have to different configurations (0x0000c458 and 0x0000c454)

  1. Configure the CAN

sudo ip link set down can0
sudo ip link set down can1
sudo ip link set can0 type can bitrate 500000
sudo ip link set can1 type can bitrate 500000

sudo ip link set can0 type can restart-ms 100
sudo ip link set can1 type can restart-ms 100

sudo ip link set up can0
sudo ip link set up can1

  1. Confirm the status of CAN with ip

ip -details -statistics link show can0
ip -details -statistics link show can1

9: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
bitrate 498701 sample-point 0.870
tq 26 prop-seg 33 phase-seg1 33 phase-seg2 10 sjw 1
mttcan: tseg1 2…255 tseg2 0…127 sjw 1…127 brp 1…511 brp-inc 1
mttcan: dtseg1 1…31 dtseg2 0…15 dsjw 1…15 dbrp 1…15 dbrp-inc 1
clock 38400000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 0 0 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0

From the information, we are facing a problem with the configuration of the baudrate which is not at 500000, but 498701. On the forums, I found “a solution”, which is to repeat the step 1 and to and change the clock parameters of the driver,. Again without any sucess…

Manipulation 2
sudo modprobe can
sudo modprobe can-raw
sudo modprobe can-dev
sudo modprobe mttcan

sudo rmmod mttcan

sudo su -c ‘echo pll_c > /sys/kernel/debug/bpmp/debug/clk/can1/parent’
sudo su -c ‘echo 34000000 > /sys/kernel/debug/bpmp/debug/clk/can1/rate’

sudo su -c ‘echo pll_c > /sys/kernel/debug/bpmp/debug/clk/can2/parent’
sudo su -c ‘echo 34000000 > /sys/kernel/debug/bpmp/debug/clk/can2/rate’

sudo modprobe mttcan
echo CAN0
sudo su -c ‘echo 34000000 > /sys/kernel/debug/bpmp/debug/clk/can1/rate’
sudo su -c ‘cat /sys/kernel/debug/bpmp/debug/clk/can1/parent’
sudo su -c ‘cat /sys/kernel/debug/bpmp/debug/clk/can1/rate’
echo CAN1
sudo su -c ‘echo 34000000 > /sys/kernel/debug/bpmp/debug/clk/can2/rate’
sudo su -c ‘cat /sys/kernel/debug/bpmp/debug/clk/can2/parent’
sudo su -c ‘cat /sys/kernel/debug/bpmp/debug/clk/can2/rate’

By repeting steps 2,3,4 we have:

10: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
bitrate 500000 sample-point 0.867
tq 29 prop-seg 29 phase-seg1 29 phase-seg2 9 sjw 1
mttcan: tseg1 2…255 tseg2 0…127 sjw 1…127 brp 1…511 brp-inc 1
mttcan: dtseg1 1…31 dtseg2 0…15 dsjw 1…15 dbrp 1…15 dbrp-inc 1
clock 34000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 0 0 0 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0

Q) Finally is there a correct way (script) to enable the CAN bus on the JETSON AGX to use it with others devices?

Thank you already for the answer and time

hello jonathan.hendriks,

for your reference, here’s developer guide, CAN (Controller Area Network). it demonstrate how to use CAN in user-space.
you may install the user app to check CAN communication, i.e. $ sudo apt-get install can-utils
by using the commands to run and check CAN packet send/receive,
for example,
broadcasting a can data packet. $ cansend <can_interface> <can_frame>;
and… receiving a can data packet, $ candump <can_interface>

please also refer to these threads as see-also. Topic 176231, and Topic 175770.

Hi Jerry, the threads explain exactly what I have been doing and do not show a solution. The event also is present in version 4.4. Any news on the subject?

Hi there, any solution yet still remaining in ERROR-ACTIVE mode even before connecting any transceiver to the JETSON??

Thank you

hi,
can you check if bitrates are same at both sides on the bus.
ip -d -s link show can0/can1
Please try with changing clock to pllaon:
https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%20Linux%20Driver%20Package%20Development%20Guide/clocks.html#wwpID0E06B0HA