How can I control CAN bus on TX2?

Hi all,

I read previous topic about CAN.

I use Jetpack 3.1 on TX2.

and I went through the following process.

  1. Inserting module.
    sudo modprobe can
    sudo modprobe can-raw
    sudo modprobe mttcan

  2. Setting CAN interface
    sudo ip link set can0 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
    sudo ip link set up can0
    sudo ip link set can1 type can bitrate 500000 dbitrate 2000000 berr-reporting on fd on
    sudo ip link set up can1

  3. Installing app can-utils
    sudo apt-get install can-utils

when I inserted module I read kern.log like below.

nvidia@tegra-ubuntu:~$ tailf /var/log/kern.log
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <info>  [1513733275.0914] manager: NetworkManager state is now CONNECTED_LOCAL
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <info>  [1513733275.1058] manager: NetworkManager state is now CONNECTED_GLOBAL
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <info>  [1513733275.1061] policy: set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <info>  [1513733275.1074] DNS: starting dnsmasq...
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <warn>  [1513733275.1191] dnsmasq[0x6f4280]: dnsmasq not found on the bus. The nameserver update will be sent when dnsmasq appears
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <info>  [1513733275.1195] device (eth0): Activation: successful, device activated.
Dec 20 10:27:55 tegra-ubuntu NetworkManager[684]: <info>  [1513733275.1706] dnsmasq[0x6f4280]: dnsmasq appeared as :1.59
Dec 20 10:27:57 tegra-ubuntu NetworkManager[684]: <info>  [1513733277.6510] manager: startup complete
Dec 20 10:27:58 tegra-ubuntu NetworkManager[684]: <info>  [1513733278.6507] WiFi hardware radio set enabled
Dec 20 10:27:58 tegra-ubuntu NetworkManager[684]: <info>  [1513733278.6508] WWAN hardware radio set enabled
Dec 20 10:31:36 tegra-ubuntu kernel: [  244.062889] can: controller area network core (rev 20120528 abi 9)
Dec 20 10:31:36 tegra-ubuntu kernel: [  244.062969] NET: Registered protocol family 29
Dec 20 10:32:01 tegra-ubuntu kernel: [  269.141130] can: raw protocol (rev 20120528)
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.504204] CAN device driver interface
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: nm_device_get_device_type: assertion 'NM_IS_DEVICE (self)' failed
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: <info>  [1513733537.0235] manager: (can0): new Generic device (/org/freedesktop/NetworkManager/Devices/5)
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]      Message RAM Configuration
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | base addr   |0x0c312000|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | sidfc_flssa |0x00000000|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | xidfc_flesa |0x00000040|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | rxf0c_f0sa  |0x000000c0|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | rxf1c_f1sa  |0x00000300|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | rxbc_rbsa   |0x00000540|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | txefc_efsa  |0x00000780|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | txbc_tbsa   |0x00000800|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518710]     | tmc_tmsa    |0x00000c80|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.518912] Release 3.2.0 from 19.12.2014
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.527176] net can0: mttcan device registered (regs=ffffff800e36a000, irq=427)
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: nm_device_get_device_type: assertion 'NM_IS_DEVICE (self)' failed
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]      Message RAM Configuration
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | base addr   |0x0c322000|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | sidfc_flssa |0x00000000|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | xidfc_flesa |0x00000040|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | rxf0c_f0sa  |0x000000c0|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | rxf1c_f1sa  |0x00000300|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | rxbc_rbsa   |0x00000540|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | txefc_efsa  |0x00000780|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | txbc_tbsa   |0x00000800|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530248]     | tmc_tmsa    |0x00000c80|
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.530429] Release 3.2.0 from 19.12.2014
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: <info>  [1513733537.0337] manager: (can1): new Generic device (/org/freedesktop/NetworkManager/Devices/6)
Dec 20 10:32:17 tegra-ubuntu kernel: [  284.536712] net can1: mttcan device registered (regs=ffffff800e370000, irq=428)
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: <info>  [1513733537.0442] devices added (path: /sys/devices/c310000.mttcan/net/can0, iface: can0)
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: <info>  [1513733537.0442] device added (path: /sys/devices/c310000.mttcan/net/can0, iface: can0): no ifupdown configuration found.
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: <info>  [1513733537.0586] devices added (path: /sys/devices/c320000.mttcan/net/can1, iface: can1)
Dec 20 10:32:17 tegra-ubuntu NetworkManager[684]: <info>  [1513733537.0586] device added (path: /sys/devices/c320000.mttcan/net/can1, iface: can1): no ifupdown configuration found.

I broadcasted a can data packet like ‘cansend can0 123#abcdabcd’ or ‘cangen can0 -I i -L 2 -D i -v -v’
(Command ‘cangen’ displayed like below.)

nvidia@tegra-ubuntu:~$ cangen can0 -I i -L 2 -D i -v -v
  can0  000   [2]  00 00
  can0  001   [2]  01 00
  can0  002   [2]  02 00
  can0  003   [2]  03 00
  can0  004   [2]  04 00
  can0  005   [2]  05 00
  can0  006   [2]  06 00
  can0  007   [2]  07 00
  can0  008   [2]  08 00
  can0  009   [2]  09 00
  can0  00A   [2]  0A 00
  can0  00B   [2]  0B 00
  can0  00C   [2]  0C 00
  can0  00D   [2]  0D 00
  can0  00E   [2]  0E 00
  can0  00F   [2]  0F 00
  can0  010   [2]  10 00
  can0  011   [2]  11 00
  can0  012   [2]  12 00
  can0  013   [2]  13 00
  can0  014   [2]  14 00
  can0  015   [2]  15 00
  can0  016   [2]  16 00

and checked the interface statistics like ‘ip -details -statistics link show can0’

nvidia@tegra-ubuntu:~$ ip -details -statistics link show can0
6: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 72 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can <BERR-REPORTING,FD> state BUS-OFF (berr-counter tx 248 rx 0) restart-ms 0 
          bitrate 500000 sample-point 0.875 
          tq 25 prop-seg 34 phase-seg1 35 phase-seg2 10 sjw 1
          mttcan: tseg1 2..255 tseg2 0..127 sjw 1..127 brp 1..511 brp-inc 1
          dbitrate 2000000 dsample-point 0.750 
          dtq 25 dprop-seg 7 dphase-seg1 7 dphase-seg2 5 dsjw 1
          mttcan: dtseg1 1..31 dtseg2 0..15 dsjw 1..15 dbrp 1..15 dbrp-inc 1
          clock 40000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          2          0          1          1          0         
    RX: bytes  packets  errors  dropped overrun mcast   
    40         5        2       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0

In the course of a cangen, I scoped out CAN0 TX pin(7 of J26).
Please watch attached pictures. It had no signal.

Both CAN0 and CAN1 had same results.

Finally, I want to watch CAN communication among CAN nodes on TX2.

How can I solve the problem?
Please answer about my question.


Hi sunyeong.jung,

Have you read below post?
[url]https://devtalk.nvidia.com/default/topic/1025630/jetson-tx2/what-is-the-order-of-communication-for-can-communication-/post/5216441/#5216441[/url]

1 Like

Thanks kayccc.

I read that post.
and I tried CAN transceiver board to do same process.

but I think CAN tx pin(ex. 7 pin of J26) should have some signal, before connecting the transceiver board, when I commend ‘cangen can0’.

Is there anything else to consider on the board or pin map and so on?

Hi

I had a similar problem

My CAN Phychip is NXP TJA1051.

It supports tow modes.(Normal : Tx,Rx / Silent : Rx)

CAN1_STBY pin is connected mode select pin on TJA1051.

CAN1_STBY pin is high after driver loaded. and TJA1051 is Silent mode.

so bus off when CAN Tx.

change my device tree below

mttcan@c310000 {
                status = "okay";
                gpio_can_stb = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 0) GPIO_ACTIVE_HIGH>;
                gpio_can_en = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 1) GPIO_ACTIVE_HIGH>;
                mram-params = <0 16 16 8 8 8 16 16 16>;
                tx-config = <8 8 0 64>;
                rx-config = <64 64 64>;
        };

        mttcan@c320000 {
                status = "okay";
                gpio_can_stb = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 6) GPIO_ACTIVE_LOW>;
                gpio_can_en = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 7) GPIO_ACTIVE_HIGH>;
                mram-params = <0 16 16 8 8 8 16 16 16>;
                tx-config = <8 8 0 64>;
                rx-config = <64 64 64>;
        };

CAN BUS working is gooooood!

1 Like

Thanks @walterkim !!

As your advice, I controlled operating mode of my transceiver.

and then. It works!!

Thank you!!

Hi all:

mttcan@c320000 {
                status = "okay";
                gpio_can_stb = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 6) GPIO_ACTIVE_HIGH>;
                gpio_can_en = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 7) GPIO_ACTIVE_HIGH>;
                mram-params = <0 16 16 8 8 8 16 16 16>;
                tx-config = <8 8 0 64>;
                rx-config = <64 64 64>;
        };

Can I change the gpio_can_stb to low in any other way?

This pin decides whether the can is in standby mode.

I tried this way:

root@tegra-ubuntu:/home/nvidia# cd /sys/class/gpio/
export       gpiochip232/ gpiochip240/ gpiochip256/ gpiochip320/ unexport     
root@tegra-ubuntu:/home/nvidia# cd /sys/class/gpio/
root@tegra-ubuntu:/sys/class/gpio# echo 302 > export 
bash: echo: write error: Device or resource busy
root@tegra-ubuntu:/sys/class/gpio#

It cannot be controlled by the gpio way.

once a driver has claimed the gpio, sysfs can not claim or control it any more.
You have to control it from the mttcan driver only in this case.
May be you can add a sysfs or debugfs node to the driver to control the gpio

Hi zhoazoz,

The gpio_can_stb pin cannot be controlled through sysfs because, you have already exported the same using mttcan in dt.

One way is to remove the dt entry and export it using sysfs, so that you have control on the direction and value through sysfs.
If you want the dt node to register the gpio_can_stb and gpio_can_en at boot, there is no user space way to modify it after boot. You can control the pin through a kernel module using the following functions,
int gpio_direction_input(unsigned int gpio);
int gpio_direction_output(unsigned int gpio, int value);
int gpio_get_value(unsigned int gpio);
void gpio_set_value(unsigned int gpio, int value);

In your case, you can write a simple kernel module with
void gpio_set_value(302, 1);

Hi,

Which file can i check for the contents below and where is it present?
mttcan@c320000 {
status = “okay”;
gpio_can_stb = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 6) GPIO_ACTIVE_HIGH>;
gpio_can_en = <&tegra_aon_gpio TEGRA_AON_GPIO(AA, 7) GPIO_ACTIVE_HIGH>;
mram-params = <0 16 16 8 8 8 16 16 16>;
tx-config = <8 8 0 64>;
rx-config = <64 64 64>;
};

@Pratosha.

The file you’re looking for is in the kernel sources:

{L4T_KERNEL_SOURCES]/nvidia_kernel_tx2/hardware/nvidia/platform/t18x/quill/kernel-dts/tegra186-quill-p3310-1000-a00-00-base.dts

Hello everyone, I have achieved the communication successfully after learning below methods.
But I also have another question, How can read data of can_rx,can_tx using C? I find out that J26 is a GPIO expender.
And do i need to read the data of pins of J26 to gain the can data?If it is right ,how should I define the number of pins,
I am looking forward to having a reference article or paper to have a guidance. Thanks a lot.

Socketcan https://en.wikipedia.org/wiki/SocketCAN

Install can-utils
https://github.com/linux-can/can-utils

$ sudo apt-get install can-utils

Candump will dump all received CAN data:

$ candump can0

(or can1, depending on which interface you’re using)

C Examples: https://www.kernel.org/doc/html/v4.17/networking/can.html

1 Like