Jetson nano MCP2515 socket CAN transmit not working

Hi All,

I 'm trying to use MCP2515 CAN extension board from waveshare on Jetson nano, I found some dts files ref to GitHub - Seeed-Studio/seeed-linux-dtoverlays: Device Tree Overlays for Seeed boards
with some modification, my latest dts file is like below:

// SPDX-License-Identifier: GPL-2.0-only
/*
 * Jetson Device-tree overlay for
 *   MCP2515
 *
 * Copyright (c) 2020 Seeed Technology Co,Ltd - https://www.seeed.cc.
 * All rights reserved.
 *
 */

/dts-v1/;
/plugin/;

#include <dt-bindings/pinctrl/pinctrl-tegra.h>
#include <dt-bindings/gpio/tegra-gpio.h>

/ {
	overlay-name = "MCP251x CAN Controller";
	jetson-header-name = "Jetson 40pin Header";
	compatible = "nvidia,p3449-0000-b00+p3448-0000-b00\0nvidia,p3449-0000-a02+p3448-0000-a02";

    

   	fragment@0 {
		target-path = "/";
		__overlay__ {
			clocks {
				can_clock: can_clock {
					compatible = "fixed-clock";
					#clock-cells = <0>;
					clock-frequency = <8000000>;
					clock-accuracy = <100>;
				};
			};
		};
	};

	fragment@1 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			spi@0 {
				status = "okay";
				compatible = "microchip,mcp2515";
				reg = <0x0>;
				spi-max-frequency = <10000000>;
				nvidia,enable-hw-based-cs;
				nvidia,rx-clk-tap-delay = <0x7>;
				clocks = <&can_clock>;
				interrupt-parent = <&gpio>;
				interrupts = <TEGRA_GPIO(S, 5) 0x1>;
				controller-data {
					nvidia,cs-setup-clk-count = <0x1e>;
					nvidia,cs-hold-clk-count = <0x1e>;
					nvidia,rx-clk-tap-delay = <0x1f>;
					nvidia,tx-clk-tap-delay = <0x0>;
				};
			};
			spi@1 {
				status = "disabled";
			};
		};
	};

	fragment@2 {
		target = <&spi1>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			spi@0 {
				status = "disabled";
			};			
			spi@1 {
				status = "okay";
				compatible = "microchip,mcp2515";
				reg = <0x0>;
				spi-max-frequency = <10000000>;
				nvidia,enable-hw-based-cs;
				nvidia,rx-clk-tap-delay = <0x7>;
				clocks = <&can_clock>;
				interrupt-parent = <&gpio>;
				interrupts = <TEGRA_GPIO(V, 0) 0x1>;
				controller-data {
					nvidia,cs-setup-clk-count = <0x1e>;
					nvidia,cs-hold-clk-count = <0x1e>;
					nvidia,rx-clk-tap-delay = <0x1f>;
					nvidia,tx-clk-tap-delay = <0x0>;
				};
			};
		};
	};

	fragment@3 {
		target = <&pinmux>;
		__overlay__ {
			pinctrl-names = "default";
			pinctrl-0 = <&jetson_io_pinmux>;

			jetson_io_pinmux: exp-header-pinmux {
				hdr40-pin19 {
					nvidia,pins = "spi1_mosi_pc0";
					nvidia,function = "spi1";
					nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin21 {
					nvidia,pins = "spi1_miso_pc1";
					nvidia,function = "spi1";
					nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin23 {
					nvidia,pins = "spi1_sck_pc2";
					nvidia,function = "spi1";
					nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin24 {
					nvidia,pins = "spi1_cs0_pc3";
					nvidia,function = "spi1";
					nvidia,pull = <TEGRA_PIN_PULL_UP>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin37 {
					nvidia,pins = "spi2_mosi_pb4";
					nvidia,function = "spi2";
					nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin22 {
					nvidia,pins = "spi2_miso_pb5";
					nvidia,function = "spi2";
					nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin13 {
					nvidia,pins = "spi2_sck_pb6";
					nvidia,function = "spi2";
					nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
				hdr40-pin18 {
					nvidia,pins = "spi2_cs0_pb7";
					nvidia,function = "spi2";
					nvidia,pull = <TEGRA_PIN_PULL_UP>;
					nvidia,tristate = <TEGRA_PIN_DISABLE>;
					nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				};
			};
		};
	};
};

Now the issue is I can only send at most 8 CAN message out from the jetson, but the receive is seems much better, you can see below picture, I connect Jetson with a VN1640 device from Vector, in the picture TX is from Canalyzer software, which is the PC, and RX is from jetson nano,

I send a lot of can message via command, “cansend can0 132#ACBA”, as you can see only first one is send out, only after the PC send another CAN message, the Jetson start send the CAN message in the buffer

and sometimes we even see “Staff error”,

Any suggestions for this issue, thanks!

Hi guopeng.sun,

What’s you Jetpack version in use?
Have you verified CAN with loopback test?

Could you help to share the block diagram from your Jetson device to host PC for CAN transmission? and the command you used to setup the CAN bus? (such as the bit rate and data rate)

Thanks for the reply.

Jetpack version: jetson-nano-jp461-sd-card-image
Loop back test not yet done, will check later.

The jetson CAN extension board schematic:

the command to setup the CAN bus:

sudo ip link set can0 up type can bitrate 125000
sudo ifconfig can0 txqueuelen 65535

the command to send CAN message in jetson nano

sudo cansend can0 123#abcabc

the block diagram from jetson to PC:

as I just registered yesterday, so I can only attach one picutre each time.

seems loopback is also not working, please ref to below picture:

I remove those two dtbo file from /boot, copy the one was generated by the dts file I shared

tegra210-p3448-0000-p3449-0000-a01-mcp251x.dtbo
tegra210-p3448-0000-p3449-0000-a02-mcp251x.dtbo

and run jetson-io.py to configure the mcp2515, thanks.

Please refer to the following thread about using MCP2515 for CAN transmission in Jetson Nano.
CanBus on the Nano - #33 by shgarg

Hi Kevin,

I checked the #33 post by shgarg, and I did the same, here is what I have done.

  1. add “spidev” in /etc/modules-load.d/modules.conf
  2. enable spi1 manually and reboot, via ```
    sudo /opt/nvidia/jetson-io/jetson-io.py
3. removed  below file from /boot

  tegra210-p3448-0000-p3449-0000-a01-mcp251x.dtbo
  tegra210-p3448-0000-p3449-0000-a02-mcp251x.dtbo
4. copied the generated 2xMCP2518FD-spi0.dtbo to /boot folder
5. run sudo /opt/nvidia/jetson-io/jetson-io.py to select the compactable hardware and select MCP251x
6. save and reboot

the hardware use pin29 as interrupt, and I selected the GPIO S 5 in the dts file.

I did all those steps with a new jetson nano with  jetson-nano-jp461-sd-card-image, still I have the transmit issue, could you please check and let me know which step is wrong, thanks.

Could you share the full serial console log or dmesg for further check?

Have you tried to use CAN transceivers in your connections?

I can share the full dmesg by tomorrow.

" tried to use CAN transceivers in your connections" if I understood correct, you mean to say connect the jetson CAN bus with another node, not the loopback mode?
I already done this by connect Jetson CAN with Vector VN1640A(laptop), same issue, every time the jetson receive a CAN message from other node, then it can send out few CAN frame in the buffer.

in jetson, use cansend can0 123#abba, to send 10 CAN message, but in the CANalyzer we may only receive 3 CAN message, if we send a CAN message from CANalyzer, then Jetson will send out maybe another 3 CAN message which was send long before via the cansend command, I will try to record a video for this tomorrow.

Thanks.

Hi Kevin,

you can find the full dmesg output here

and a video here.

You could refer to the following about our verification for CAN bus (although it is verified with AGX Xavier, but we set up with CAN transceivers)
Jetson AGX Xavier Developer Kit CAN commmunication error - #8 by KevinFFF

Does you issue about the data been delayed received?

Could you help to verify with latest R32.7.4?

and also check if the CS pin for MCP2515 work as expected?

Hi Kevin,

I checked all the related pins with a logic pro 16, here is some pictures, please help check:
the setting:
image

I send 6 CAN message via cansend in jetson nano, but none of them was send to the CAN bus,
after send a CAN message via CANalyzer, Jetson send out 5 CAN message + a error message

overall waveform:

at 8s 90ms, we received the CAN message send from the laptop


the IRQ pin voltage changed from 3.3V to 1.7V after the CAN message was transmited to CAN bus;

at 8s 106ms, the IRQ pin goes to 0.5V, but no SPI message was transmitted, the Jetson start transmit the first CAN message with staff error, then it start the next one,

the first SPI message was send out at around 8s 107ms, later than the CAN message

Seems the CS pin and IRQ pin are both working?

Could you please help check and share your comments, thanks.

I changed the maximum clk frequency to 1000000 hz, and reboot the jetson, still I have the same issue, here you can see some pictures of the waveform:
also I exported the decoded data for SPI and CAN, please note, logic pro has issue to decode CAN low signal, so sometimes the decoded data was not correct
jetson nano mcp2515 issue.csv (10.9 KB)

I send three CAN message in Jetson,


in Canalyzer receive 1 CAN message, after send a CAN message in Canalyzer, the other two was received

at 4s 835ms, the jetson send out the SPI message to MCP2515, the first CAN message was successfully transmited, the logic pro has some issue to decode the CAN Low sometime, in CANalyzer the message was received without issue.

at 5s 409ms, same SPI message was send to mcp2515, but nothing happened on CAN bus

at 10s 310ms
CANalyzer send out a CAN message, after that the other two send out from Jetson MCP

the second CAN message send from jetson was before the SPI message

please check and share your comments!

BTW, I don’t see any sdcard image for jetson nano based on R23.7.4, if you could provide a link then I can try tomorrow, thanks.

Hi

The link you shared is for Xavier, I think the first few steps “1. Configure pinmux for CAN bus through Jetson IO” was not compatible to jetson nano

I do not see much difference from step 3, only the berr-reporting on is not support by jetson nano, you can ref to below one

Please share your comments, thanks.

Do you suspect the issue causing from IRQ 1.7V?

Sorry that we don’t have MCP2515 module could do a local reproduce and debug.

Although you are using the custom board, you could also try using SDKM to flash your board if there’s no much difference in board design.

Could you help to use candump to receive the data instead?

Hi Kevin,

I’m not familar with MCP2515, can not judge whether this is a issue or not.

I have other linux board which also has MCP2515, and working without issue with the socketcan interface.
I compared the source code of mcp2515 driver, do not see much difference.
Assume that the issue is more like a DTS issue, could you please help again double check my DTS, because I was new to linux device driver and jetson device, so I’m not sure wther the DTS is correct or not?

I used the candump also in loopback mode, same issue, right now I’m using a laptop with a VN1640A from Vector, which should not be a problem.

I will try to update it to R23.7.4 via SDKM, and let you know whether it works.

The supplier of the mcp2515(waveshare) provide a python script based on spidev, which is working fine without issue, so hardware should be OK.

BTW, if you agree I can ship one MCP2515 module to you, so that you can try it with your own jetson nano, because this is really very important to our project, thanks again for the support!

Best Regards,
Guopeng

I just checked again your device tree configuration for MCP2515 and it seems as expected.
In addition, I found the level for MOSI/MISO/CLK seems lower not reach 3.3V.

Do you have the devkit with the same behavior?

Ref to the datasheet of mcp2515, the SCK/MISO is low than VDD, which is 3.3V in my case, so thise should not be a problem.

I checked the R23.7.4, the CAN is not working, same dts file, in loopback mode, the message was not received, thanks.

Could you help to apply the following patch to check if it could help?
It is the fix for CS pin and it might affect your MCP2515 function.
https://forums.developer.nvidia.com/t/spi-tpm-module-support-fail-on-jetpack-5-0-2-5-1-on-jetson-xavier-agx/241096/25S