how can I use CAN bus in TX2?

I use ifconfig -a in terminal,the result does not show any can bus . And There is no can device in /dev/ path, I would like to ask how can I use CAN bus in TX2? Should I rebuild the kernel?

Does your carry board are customized board? Otherwise you should see the eth0 by ifconfig like below.

eth0      Link encap:Ethernet  HWaddr 00:04:4b:81:c7:1f
          inet addr:10.19.106.126  Bcast:10.19.107.255  Mask:255.255.254.0
          inet6 addr: fe80::38b:bd35:5dcb:445d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4281828 errors:0 dropped:1 overruns:0 frame:0
          TX packets:939227 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3230501733 (3.2 GB)  TX bytes:91281150 (91.2 MB)
          Interrupt:39

Thank you for your attention.
Right now I am using the official standard carry board,after ifconfig command , I can see eth0 and lo details just like you.My Question is where should I find can0 and can1 devices,And How can I use these interfaces? By Socket or By Char device?

That’s an Ethernet interface, not a CAN interface.

I don’t think the Linux kernel by default sets up network devices for CAN; it only uses tty-like devices to talk to the controller.

If you want to treat it like a network, you need to install something like SocketCAN (I haven’t been in this area for ages.)

The CAN-related modules that are available are:

/lib/modules/4.4.15-tegra/kernel/drivers/net/can
/lib/modules/4.4.15-tegra/kernel/drivers/net/can/vcan.ko
/lib/modules/4.4.15-tegra/kernel/drivers/net/can/slcan.ko
/lib/modules/4.4.15-tegra/kernel/drivers/net/can/can-dev.ko
/lib/modules/4.4.15-tegra/kernel/net/can
/lib/modules/4.4.15-tegra/kernel/net/can/can-raw.ko
/lib/modules/4.4.15-tegra/kernel/net/can/can-bcm.ko
/lib/modules/4.4.15-tegra/kernel/net/can/can-gw.ko
/lib/modules/4.4.15-tegra/kernel/net/can/can.ko

“sudo modprobe can-raw” seems to install something, but I don’t have any gear to test it.
Try looking in that direction!

Thank you for your attention.
I have found those CAN-related modules.
/lib/modules/4.4.15-tegra/kernel/drivers/net/can
/lib/modules/4.4.15-tegra/kernel/drivers/net/can/vcan.ko
/lib/modules/4.4.15-tegra/kernel/drivers/net/can/slcan.ko
/lib/modules/4.4.15-tegra/kernel/drivers/net/can/can-dev.ko
/lib/modules/4.4.15-tegra/kernel/net/can
/lib/modules/4.4.15-tegra/kernel/net/can/can-raw.ko
/lib/modules/4.4.15-tegra/kernel/net/can/can-bcm.ko
/lib/modules/4.4.15-tegra/kernel/net/can/can-gw.ko
/lib/modules/4.4.15-tegra/kernel/net/can/can.ko
sudo modprobe can-raw return nothing.
Through lsmod command,there is can_raw can can_dev modules in the Module list,BUT I still can not see any can0/can1 device by ifconfig -a or in the /dev/ path,does anybody knows why ???

I am also interested in this.

I think what we really need is a description of how to configure the CAN controllers in the Jetson from the software side. The driver modules seem to be there, but I can’t find any documentation on which ones I should be installing to get the devices to show up, and what API the devices will expose.

Hi GREENSKY and snarky,

Yes, the driver module was included in current BSP, however that’s not validated before the release, and might have potential issues that we don’t know yet.

If you want to get it a try, please enable the below config to get driver enabled:
CONFIG_MTTCAN=m

Thanks

Thank you for your attention.
I am really eager to use the can bus now.
Can you show me how to enable the config “CONFIG_MTTCAN=m” in detail?
Should I rebuild the kernel or just change some configuration?

Hi Greensky
You need add this config to tegra18_defconfig and rebuild the kernel and apply it by replace /boot/Image .

I assume this will be included by default in the next Jetpack?

Snarky
Yes, it’ll be included by default by next release.

Hi I have just compiled the kernel to enable the can0 and can1
I can see the can0, can1 by ifconfig -a
If I want to use the can bus do i need extra hardware or can I simply connect the can rx,tx from the radio head to J26 pin?

No, you need a transciever chip to convert to CAN electrical standdard (CANH/CANL)
These chips cost a few dollars, soldered onto circuit boards with pin headers.
Check eBay for example.

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?

Are you using a transceiver chip? If not and you are directly probing the header pins, the controller will immediately go into error state, check with dmesg. Without a transceiver, a few external “CAN without a transceiver” components are needed simulating the bus.

can anyone suggest which transceiver to use, that you have experience with tx2.
thanks

Hi gyuhyong,

I am using a pair of TI SN65HVD257 transceivers with my TX2 board, and they are working fine.

Thanks,

Chris Richardson

Thanks cjwti
can you briefly explain the diagram of your wiring?
I found that there are six connectors 3v3 and GND pretty sure they are power
CTX, CRX, CANH, CANL. Which one should connect to which part of jetson and the car.
I found that I can access to the CANH and CANL in my car by the wire from the radio head

CTX and CRX go to the Jetson pin header “TX” and “RX” for the CAN bus.
3.3V goes to Jetson (or some other) 3.3V for power-out.
GND goes to Jetson GND, preferrably a pin as close to the Can TX/RX as possible.

CANH and CANL are the CAN bus wires. All CAN devices on the same bus connect their CANH to the CANH wire and their CANL to the CANL wire.

Depending on how fast you want to go, different max buss lengths are recommended, and you may need to make sure the buss is terminated for higher speeds. Here’s a reasonable description: http://www.ni.com/white-paper/9759/en/

thanks a lot for the description
which sound like I only need one transceiver to get the data is that correct?
according to the link I need a register is that correct understanding?
I am going to use rate of 500k