TX2 CAN bus read

Hi,

To further what was discussed in the following thread,

https://devtalk.nvidia.com/default/topic/1002435/jetson-tx2/obd-can-bus-connector-tx2-bmw/

  1. What are the ports to which CAN0 and CAN1 are connected to? (For instance, UART1 is connected to /dev/ttyTHS2 port)

  2. Can CAN data be read in the same way as from the Serial port (given below example) from the relevant ports?


#Python Serial Port example

ser1 = serial.Serial(’/dev/ttyTHS2’,9600,bytesize=8,parity=‘N’,stopbits=1, timeout=None, xonxoff=False, rtscts=True, dsrdtr=True )

ser1.read()


Any wisdom on this is appreciated.

There’s a previous thread that suggests that the CAN port drivers don’t properly load in Jetpack 27.1, and we have to wait for the next release to actually be able to talk to the CAN hardware.
It may be that we actually have all the bits and pieces available to talk CAN on the current version of Jetpack; we just haven’t found any documentation from NVIDIA on how to do it.

When you can talk to the CAN hardware, that hardware is more of a network and less of a raw pipe, so it won’t work exactly like a serial port. Instead, check out SocketCAN for Linux.
https://en.wikipedia.org/wiki/SocketCAN

See if you can make it work using modprobe:

sudo modprobe can can_gw can_bcm can_raw can_dev slcan vcan

and use “ip” to add the interface.

Thanks, snarky.

Hi,

I can confirm that I am able to send data across a CAN bus from the TX2 to a separate board. You will need the transceivers of course at each end. I am using a small board with a pair of TI SN65HVD257 transceivers on it (along with required external components). Sending data with the Linux SocketCAN interface is relatively easy as can be seen in the documentation at https://www.kernel.org/doc/Documentation/networking/can.txt. Note that I haven’t done much testing with this setup yet as I just started working on it yesterday, but it does seem possible.

Thanks,

Chris Richardson

Oh, that’s great!

Aside: one can use sigrok and pulseview (both free) and a $20-40 set of chips and cables to perform real-time signal analysis WITH protocol translations, even on a lowly RPi but can store way more points (into the billions) with a desktop. There are dozens of protocols this software can handle, including rs232 serial, of course, and I2C, SPI, and CAN, of today’s popular ones. So you can use those tools to verify the signals between the TXx’s and the targets.
Basically, it is a software-defined logic analyzer of tremendous capability. For $20-40.

FYI, link to SocketCAN driver source for R27.1: https://github.com/hartkopp/nvidia-t18x-can

Thanks everybody.
One quick question.
How do you install this driver on TX2?
Is it just running make install?

Hi,

It’s just a bit of busy work. You have to edit the kernel configuration and install the new kernel and modules on your TX2 board somehow. In my case, I edited the kernel configuration then just copied the Image file, modules and dtbs over to the board. Then I rebooted it and saw my new kernel was running.

The following thread has some information on how to do this.

https://devtalk.nvidia.com/default/topic/1006762/jetson-tx2/how-can-i-use-can-bus-in-tx2-/post/5140774/

However I also found the documentation to be very helpful. In the following download there is a file nvl4t_docs\Tegra Linux Driver Package Development Guide\l4t_getting_started.html, which contains a section titled “Building the NVIDIA Kernel”. You will want to follow these instructions very carefully.

http://developer.download.nvidia.com/embedded/L4T/r27_Release_v1.0/Docs/Tegra_Linux_Driver_Package_Documents_R27.1.tar

Once you have the kernel built with CAN support, you will need to load the driver modules. Since I am going to use raw CAN, the following is all I needed. You might need other modules depending on what you are doing.

sudo modprobe mttcan
sudo modprobe can

After that you should be able to see the CAN interfaces with the ‘ip link’ command. If you can see them listed, then you can configure them and bring them up:

sudo ip link set can0 type can bitrate 1000000
sudo ip link set up can0

Now you can take a look at the Linux SocketCAN documentation I pointed to earlier in the thread for how to create sockets which can be used to communicate over the CAN bus.

Thanks,

Chris Richardson

Hi, I have add CONFIG_MTTCAN=m to open can0 & can1 in kernel;
I also add below code in dtsi file to open relationship between can controller and IO port :

can1_dout_pz0 {
				nvidia,pins = "can1_dout_pz0";
				nvidia,function = "can1";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};

			can1_din_pz1 {
				nvidia,pins = "can1_din_pz1";
				nvidia,function = "can1";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_ENABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

			can0_dout_pz2 {
				nvidia,pins = "can0_dout_pz2";
				nvidia,function = "can0";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};

			can0_din_pz3 {
				nvidia,pins = "can0_din_pz3";
				nvidia,function = "can0";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_ENABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

But when I use can-utils tools from https://github.com/linux-can/can-utils to send can message ,I did not receive any error message, but Using oscilloscope, I still can not find any signal changed in CANx_TX ports.
What else need to be do?

Thanks, Chris.
Built the kernel with CAN support and the CAN interfaces show up.
Will look at SocketCAN now.

For what it’s worth, if someone wants to avoid having to build it themselves, I made the module available pre-built for download:

https://watte.net/tegra-27.1-mttcan.tgz

Hopefully it’s already available in the next Jetpack, so the need for this archive should be short-lived.

if you mean that you build kernel in Liunx PC, and it will produce Image, dtb and modules lib, and you just copy it to the TX2, I want to know the complete direction of your copy, thanks

Hi,

If you are asking for complete instructions on how to copy the kernel image, dtb and modules from the Linux host to the TX2, unfortunately I won’t be able to send that. I would really suggest reading the “Building the NVIDIA Kernel” section of the documentation I linked to in the post you quoted. It shows you where all the files are placed after building the kernel, and from there I think it is straightforward to copy them over to the TX2.

Thanks,

Chris Richardson

Hi, I am also trying to get the CAN socket working on the Jetson TX2. I am running from Jetpack 3.3, do I still need to install a driver for the CAN interface?

Currently, I would just like to know how I can view the available CAN interface ports from my computer.