Controller Area Network (CAN)#

Applies to: Jetson Thor, Jetson AGX Orin, Jetson Orin NX, and Jetson Orin Nano product families.

This topic describes the Time Triggered CAN (TTCAN) controller of the NVIDIA® SoC, and how to use it in user space.

Important Features#

The Time Triggered CAN controller has several important features:

  • It supports standard and extended frame transmission.

  • CAN bus bit rate can be configured from 10 kbps to 1 Mbps.

  • Jetson Thor can achieve up to 8 Mbps data bit rate. All other platforms can achieve up to 15 Mbps data bit rate.

Jetson Platform Details#

The following table shows details of the CAN implementation on each supported platform.

Property Jetson Orin NX and Nano Jetson AGX Orin Jetson Thor
Number of controllers 1 2 2
Controller base address mttcan@c310000 mttcan@c310000
mttcan@c320000
mttcan@81102f0000
mttcan@8110300000
Pins on Jetson carrier board J17:
 CAN_RX: [1]
 CAN_TX: [2]
J30 (40-pin header):
 CAN0_DIN: [29]
 CAN0_DOUT: [31]
 CAN1_DIN: [37]
 CAN1_DOUT: [33]
J47 (2*13 pin header):
 FSI_CAN0_H: [3]
 FSI_CAN0_L: [5]
 FSI_CAN1_H: [7]
 FSI_CAN1_L: [9]
Pinmux can0_din Addr: 0x0c303018
Value: 0xc458
Addr: 0x0c303018
Value: 0xc458
Addr: 0x8110310000
Value: 0xc458
Pinmux can0_dout Addr: 0x0c303010
Value: 0xc400
Addr: 0x0c303010
Value: 0xc400
Addr: 0x8110310020
Value: 0xc400
Pinmux can1_din n/a Addr: 0x0c303008
Value: 0xc458
Addr: 0x8110311000
Value: 0xc458
Pinmux can1_dout n/a Addr: 0x0c303000
Value: 0xc400
Addr: 0x8110311020
Value: 0xc400
Default pin configuration SFIO: CAN functionality GPIO SFIO: CAN functionality

How to Enable CAN#

The interface from an NVIDIA Jetson device to CAN requires a transceiver that supports a minimum of 3.3 V and a transfer rate based on the Jetson platform’s specifications, except for Jetson Thor, which has built-in transceivers. For details, see the section Important Features.

NVIDIA recommends the WaveShare SN65HVD230 CAN board for development systems that require external transceivers. Your choice of transceiver for production devices depends on your application’s requirements.

Connections for the Jetson AGX Orin, Jetson Orin NX, and Jetson Orin Nano are as follows:

  • Transceiver Rx to Jetson CAN_RX

  • Transceiver Tx to Jetson CAN_TX

  • Transceiver VCC to Jetson 3.3V pin

  • Transceiver GND to Jetson GND pin

This diagram shows an example of a correct connection:

A CAN network correctly connected

Connections for the Jetson Thor carrier board:

  • For CAN0 bus termination:
    • J47 (2x13 pin header): Short pin 3 FSI_CAN0_H and pin 4 FSI_CAN0_TERM.

  • For CAN1 bus termination:
    • J47 (2x13 pin header): Short pin 7 FSI_CAN1_H and pin 8 FSI_CAN1_TERM.

To connect CAN0 and CAN1 in loopback:

  • J47 (2x13 pin header): Short pin 3 FSI_CAN0_H and pin 7 FSI_CAN1_H.

  • J47 (2x13 pin header): Short pin 5 FSI_CAN0_L and pin 9 FSI_CAN1_L.

Kernel DTB#

By default, CAN DTB nodes are enabled in the kernel device tree.

  • For the Jetson AGX Orin, Jetson Orin NX, and Jetson Orin Nano:

    mttcan@c310000 {
        status = "okay";
    };
    mttcan@c320000 {
        status = "okay";
    };
    
  • For the Jetson Thor carrier board:

    mttcan@81102f0000 {
        status = "okay";
    };
    mttcan@8110300000 {
        status = "okay";
    };
    

Pinmux#

For Jetson Thor: No pinmux updates are required because the pins are configured for CAN functionality by default.

For Jetson AGX Orin, Jetson Orin NX, and Jetson Orin Nano platforms: Ensure that the pinmux register settings are applied as shown by the table in the section Jetson Platform Details.

Pinmux can be updated in several ways:

  • Use a BusyBox devmem tool to write to hardware registers. Changes will persist only until the system is rebooted.

    Enter this command to install BusyBox:

    $ sudo apt-get install busybox
    

    This example writes the value 0x458 to register address 0x0c303020:

    $ busybox devmem 0x0c303020 w 0x458
    
  • Update the respective platform pinmux configuration files and flash the updated files.

  • See Running Jetson-IO, in the topic Configuring the Jetson Expansion Headers, for information about how to enable pins.

Load the CAN Kernel Drivers#

Load all of the necessary CAN kernel drivers in the order shown.

  1. Insert the CAN BUS subsystem support module:

    $ modprobe can
    
  2. Insert the raw CAN protocol module (CAN-ID filtering):

    $ modprobe can_raw
    
  3. Add real CAN interface support (for Jetson, mttcan):

    $ modprobe mttcan
    

Manage the Network#

To use the network, you must first bring up CAN devices on the network and install a group of CAN utilities to use for testing. Then you can transfer packets and debug the network interface if necessary.

Set the interface properties#

  • These example commands set the network interface to use FD (Flexible Data) mode with a bus bit rate of 500 kbps and a data bit rate of 1 Mbps:

    $ ip link set can0 up type can bitrate 500000 dbitrate 1000000 berr-reporting on fd on
    $ ip link set can1 up type can bitrate 500000 dbitrate 1000000 berr-reporting on fd on
    

Install the CAN utilities#

  • Enter the command:

    $ sudo apt-get install can-utils
    

Transfer Packets#

  • This example command transfers a packet to can0 with CAN ID 123 and data ‘abcdabcd’:

    $ cansend can0 123#abcdabcd
    
  • This example command receives a packet from any CAN node connected to the bus:

    $ candump -x any &
    
  • This example command transfers an FD frame to can0 with CAN ID 123, flag bit 1, and data ‘abcdabcd’:

    $ cansend can0 123##1abcdabcd
    

For more information about the use of cansend, enter this command:

$ cansend --help

You can use other tools, such as cangen, for different filtering options.

Debug Methods#

This section discusses methods of debugging CAN network problems.

Loopback Test#

You can perform a internal loopback test to determine whether the controller is working.

To perform a loopback test, enable the CAN drivers. (For more information, see Load the CAN Kernel Drivers.)

$ ip link set can0 type can bitrate 500000 loopback on
$ ip link set can0 up
$ candump can0 &
$ cansend can0 123#abcdabcd

If the loopback test is successful, the last command displays this:

can0 123 [4] AB CD AB CD
can0 123 [4] AB CD AB CD

Other Methods#

Several other debugging techniques may be useful in appropriate cases:

  • If a loopback test shows that the controller is working correctly and you are still not able to send or receive packets, try reconnecting the transceiver and confirm that the connections are correctly made.

  • Check whether all of the steps necessary to enable CAN were done properly.

  • Connect an oscilloscope and see whether the bus is behaving properly.

  • If the device logs a “No buffer space available” message during send, enter this command to use the polling mechanism:

    $ cangen -L 8 can0 -p 1000
    

Obtain Higher Bit Rates#

This section applies only to Jetson AGX Orin, Jetson Orin NX, and Jetson Orin Nano platforms. It is not required for Jetson Thor.

You can obtain higher data bit rates by configuring the TDCR (Transmission Delay Compensation Register) through its user space sysfs node.

Make sure that the transceiver being used is able to support higher bit rates.

Configure TDCR#

  1. Enter the command:

    $ echo 0x600 > /sys/devices/c320000.mttcan/net/can1/tdcr
    
  2. Bring up the CAN interface on the network and transfer packets. See Managing the Network for more information.

Change the CAN Clock Rate#

This section applies only to Jetson AGX Orin, Jetson Orin NX, and Jetson Orin Nano platforms. Jetson Thor CAN clock rate is fixed at 40 MHz.

The mttcan kernel driver sets the CAN clock rate. Follow the instructions in Obtaining the Kernel Sources with Git in the topic Kernel Customization to obtain kernel source code. Update the clock rate in the mttcan driver as in this code snippet:

.set_can_core_clk = true,
.can_core_clk_rate = 50000000, // modify here (in Hz)
.can_clk_rate = 200000000,     // four times of core clock rate

The default CAN clock rates are as follows:

  • Jetson Orin (AGX, NX, and Nano) product family: 50 MHz

  • Jetson Thor product family: 40 MHz