Jetson orin and mcp2518fd can module

Hey
I want to communicate with my jetson orin and mcp2518fd can module over spi.
can anyone give me a step by step guide from scratch
Thank you

you require a CAN transciever to connect to the orin first, something like the CJMCU-1051 CAN Transceiver would be suitable

You can also refer to Controller Area Network (CAN) — Jetson Linux Developer Guide documentation (nvidia.com)

thanks,but I would like to use SPI driver MCP2518FD, which doesn’t seem to be mentioned

hello,I want to enable mcp2518fd(spi can) on orin.

Hi,
We don’t have experience about using the device, so for enabling the driver, it would need other users to share experience.

If you connect the device to SPI1, you can try to enabled it through jetson-io.py. If you use other SPI interface, please refer to the dtb file generated through jetson-io.py, and modify device tree per your design.

ok,thank you reply,please keep this topic open for now, thank you

hi,I successfully loaded mcp2518fd after I modified the device tree,I can use this instruction to start can0, but it does not communicate with can1, can2, and I tried to loopback the test failed.

titan@titan:/proc/sys/net/ipv4/conf/can2$ sudo dmesg |grep mcp
[ 14.710400] mcp251xfd spi2.0 can0: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:20.00MHz m:10.00MHz r:8.50MHz e:0.00MHz) successfully initialized.

titan@titan:~$ sudo ip link set can0 up type can bitrate 500000 restart-ms 5000
titan@titan:~$ ifconfig
can0: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 68

can1: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 4 bytes 16 (16.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 16 (16.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 121

can2: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 1 bytes 4 (4.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1 bytes 4 (4.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 122

root@titan:/home/titan# ip link set can0 type can bitrate 50000 loopback on
RTNETLINK answers: Operation not supported

I wonder if you can give me some help. Thank you.

Hi @Seven0
do you have any progress? I have the same issue.

interrupts = <TEGRA234_AON_GPIO(BB, 1) IRQ_TYPE_LEVEL_LOW>;
Check that the interrupt pin and clock frequency is set correctly ,It needs to be the same as on the your board
clock-frequency = <40000000>;

Thanks for your quickly response,
I have confirmed that my interrupt setting is correct.
Can you share your mcp2518 dts? I think there should some error of my mcp2518 dts.
Many Thanks

can_clock: can_clock {
compatible = “fixed-clock”;
#clock-cells = <0>;
clock-frequency = <40000000>;
clock-accuracy = <100>;
};

spi@3230000{ /* SPI3 */
	status = "okay";

	can@0 {		
		compatible = "microchip,mcp251xfd";
		reg = <0x0>;
		clocks = <&can_clock>;
		spi-max-frequency = <50000000>;
		interrupt-parent = <&tegra_aon_gpio>;
		interrupts = <TEGRA234_AON_GPIO(BB, 1) IRQ_TYPE_LEVEL_LOW>;
		controller-data {
			nvidia,enable-hw-based-cs;
			nvidia,cs-setup-clk-count = <0x1e>;
			nvidia,cs-hold-clk-count = <0x1e>;
			nvidia,rx-clk-tap-delay = <0x1f>;
			nvidia,tx-clk-tap-delay = <0x0>;
		};
	};

Hi @Seven0,

There should be CAN transceiver included in MCP251x module.

Could your MCP2518fd work with this device tree configuration?
Is there still any issue with CAN transmission?
If so, please share the result of dmesg and sudo ip -d -s link show can0.

Hi @kang.pan
Are you also using AGX Orin and MCP2518FD module on spi@3230000?
Please also share your dmesg and sudo ip -d -s link show can0 for further check.

hello,
There is a problem with sending data. In max power mode, loop sending data without delay has an error:
write: No buffer space available
When data is sent in loop,short can_h and can_l , it can self-recovery , but cannot be self-recovery after a period of time.This is a self-recovery log. You cannot print this log without self-recovery
[ 3090.671888] mcp2518fd spi2.0 can0: bus-off, scheduling restart in 5000 ms
[ 3095.794631] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3095.797232] mcp2518fd spi2.0 can0: bus-off, scheduling restart in 5000 ms
[ 3100.906613] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3100.910984] mcp2518fd spi2.0 can0: bus-off, scheduling restart in 5000 ms
[ 3106.025807] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 3106.029616] mcp2518fd spi2.0 can0: bus-off, scheduling restart in 5000 ms

This is sudo ip -d -s link show can0:
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 minmtu 0 maxmtu 0
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 5000
bitrate 500000 sample-point 0.875
tq 25 prop-seg 34 phase-seg1 35 phase-seg2 10 sjw 1
mcp251xfd: tseg1 2…256 tseg2 1…128 sjw 1…128 brp 1…256 brp-inc 1
mcp251xfd: dtseg1 1…32 dtseg2 1…16 dsjw 1…16 dbrp 1…256 dbrp-inc 1
clock 40000000
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

Is there the issue during receiving the data?

Could you share the result of the following command when you hit this issue?

$ sudo ip -d -s link show can0

hello,
Receiving data no issue,it is the result of the command when i hit this issue:
sudo ip -d -s link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 minmtu 0 maxmtu 0
can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 5000
bitrate 500000 sample-point 0.875
tq 25 prop-seg 34 phase-seg1 35 phase-seg2 10 sjw 1
mcp251xfd: tseg1 2…256 tseg2 1…128 sjw 1…128 brp 1…256 brp-inc 1
mcp251xfd: dtseg1 1…32 dtseg2 1…16 dsjw 1…16 dbrp 1…256 dbrp-inc 1
clock 40000000
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
146694 48796 61 0 61 0
TX: bytes packets errors dropped carrier collsns
94422 31474 0 0 0 0

Hi @KevinFFF ,

I am using AGX Orin DevKit and MCP2518FD module on DevKit J30(40Pin to outside) spi (spi@3210000).
Sorry, my phenomenon is not exactly the same as @Seven0.

The can 0 on my device can not be set up.
The error message always:

rk@Orin:~$ sudo ip link set can0 up
RTNETLINK answers: Connection timed out

and the dmesg log says:

[   55.868653] mcp251xfd spi0.0 can0: Controller failed to enter mode CAN 2.0 Mode (6) and stays in Configuration Mode (4).

My dts is same as @Seven0, below are my operation and logs on my device:

rk@Orin:~$ sudo dmesg | grep spi
[   14.512551] spi-tegra114 3210000.spi: Adding to iommu group 2
[   14.521876] spi-tegra114 3230000.spi: Adding to iommu group 2
[   15.369829] spi_master spi0: will run message pump with realtime priority
[   15.382213] mcp251xfd spi0.0: can_rx_offload_init_queue: skb_queue_len_max=512
[   15.392699] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:40.00MHz r:17.00MHz e:0.00MHz) successfully initialized.
rk@Orin:~$ 
rk@Orin:~$ sudo ip link set can0 type can bitrate 500000
rk@Orin:~$ sudo ip link set can0 up
RTNETLINK answers: Connection timed out
rk@Orin:~$ 
rk@Orin:~$ sudo dmesg | grep spi
[   14.512551] spi-tegra114 3210000.spi: Adding to iommu group 2
[   14.521876] spi-tegra114 3230000.spi: Adding to iommu group 2
[   15.369829] spi_master spi0: will run message pump with realtime priority
[   15.382213] mcp251xfd spi0.0: can_rx_offload_init_queue: skb_queue_len_max=512
[   15.392699] mcp251xfd spi0.0 can0: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:40.00MHz r:17.00MHz e:0.00MHz) successfully initialized.
[   55.851105] mcp251xfd spi0.0 can0: FIFO setup: TEF: 8*12 bytes = 96 bytes, TX: 8*16 bytes = 128 bytes
[   55.851117] mcp251xfd spi0.0 can0: FIFO setup: RX-0: 32*20 bytes = 640 bytes
[   55.851119] mcp251xfd spi0.0 can0: FIFO setup: free: 1184 bytes
[   55.868653] mcp251xfd spi0.0 can0: Controller failed to enter mode CAN 2.0 Mode (6) and stays in Configuration Mode (4).
rk@Orin:~$ 
rk@Orin:~$ sudo ip link set can0 type can bitrate 50000 loopback on
RTNETLINK answers: Operation not permitted
rk@Orin:~$ 
rk@Orin:~$ sudo ip -d -s link show can0
4: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 minmtu 0 maxmtu 0 
    can state STOPPED (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 500000 sample-point 0.875 
	  tq 25 prop-seg 34 phase-seg1 35 phase-seg2 10 sjw 1
	  mcp251xfd: tseg1 2..256 tseg2 1..128 sjw 1..128 brp 1..256 brp-inc 1
	  mcp251xfd: dtseg1 1..32 dtseg2 1..16 dsjw 1..16 dbrp 1..256 dbrp-inc 1
	  clock 40000000 
	  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 

Hi @Seven0,

Could you help to apply the following patch and check if it could help for your case?
MTTCAN on Orin NX issues - #22 by KevinFFF

Hi @kang.pan,
You should load can driver as following before setup can0.

sudo modprobe mttcan

Please refer to this instruction to setup and verify can.

Hi @KevinFFF ,
Sorry, I don’t understand why need to load mttcan driver.
In my understand, there is no relationship between mcp2518 and mttcan.

After I load mttcan, the mcp2518 can dev is can2.
I follow the instruction, to test the mcp2518 (can2), the error is same as before:

rk@Orin:~$ sudo modprobe can
rk@Orin:~$ sudo modprobe can_raw
rk@Orin:~$ sudo modprobe mttcan 
rk@Orin:~$ sudo modprobe mcp251xfd 
rk@Orin:~$ 
rk@Orin:~$ sudo dmesg | grep can
[ 2284.857895] can: controller area network core
[ 2288.629217] can: raw protocol
[ 2293.975512] net can0: mttcan device registered (regs=000000001ae3c7a3, irq=115)
[ 2293.979358] net can1: mttcan device registered (regs=00000000ab3b8d60, irq=116)
[ 2298.437551] mcp251xfd spi0.0: can_rx_offload_init_queue: skb_queue_len_max=512
[ 2298.444562] mcp251xfd spi0.0 can2: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:40.00MHz r:17.00MHz e:0.00MHz) successfully initialized.
rk@Orin:~$ 
rk@Orin:~$ sudo ip link set can2 up type can bitrate 500000 dbitrate 1000000 berr-reporting on fd on
RTNETLINK answers: Connection timed out
rk@Orin:~$ 
rk@Orin:~$ sudo dmesg | grep spi
[ 2298.437551] mcp251xfd spi0.0: can_rx_offload_init_queue: skb_queue_len_max=512
[ 2298.444562] mcp251xfd spi0.0 can2: MCP2518FD rev0.0 (-RX_INT -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD c:40.00MHz m:40.00MHz r:17.00MHz e:0.00MHz) successfully initialized.
[ 2327.447298] mcp251xfd spi0.0 can2: FIFO setup: TEF: 4*12 bytes = 48 bytes, TX: 4*72 bytes = 288 bytes
[ 2327.447309] mcp251xfd spi0.0 can2: FIFO setup: RX-0: 16*76 bytes = 1216 bytes
[ 2327.447311] mcp251xfd spi0.0 can2: FIFO setup: free: 496 bytes
[ 2327.450731] mcp251xfd spi0.0 can2: Controller failed to enter mode Mixed (CAN FD/CAN 2.0) Mode (0) and stays in Configuration Mode (4).