How to enable MCP2515 on Xavier-NX

Hi,

Our carrier board with Xavier-NX has one canbus,I want to use mcp2515,which communicate to canbus.

BSP:JetPack4.4 R32.4.3
Module: Xavier-NX with emmc

mcp2515 Xavier-NX
INT 112 (SPI1_CS1)
SCK 106 (SPI1_SCK)
SI 104 ((SPI1_MOSI)
SO 108 SPI1_MISO)
CS 110 (SPI1_CS0)
GND GND
VCC VDD_3V3

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

spi@3230000{ /* SPI3 in 40 pin conn */
spi@0 {
status = “okay”;
compatible = “microchip,mcp2515”;
reg = <0x0>;
spi-max-frequency = <10000000>;
nvidia,enable-hw-based-cs;
clocks = <&can_clock>;
interrupts = <TEGRA194_MAIN_GPIO(Y, 4) 0x1>;
};
};

gpio@2200000 {
mcp2515_init {
gpio-hog;
input;
gpios = <TEGRA194_MAIN_GPIO(Y, 4) 0x1>;
label = “mcp2515_init”;
status = “okay”;
};
};
};

I got the message below.

$sudo ip link set can1 up type can bitrate 500000
RTNETLINK answers: Invalid argument

[ 2338.558410] mcp251x spi2.0: failed to get GPIO from device tree
[ 2338.570893] mcp251x spi2.0 can1: MCP2515 successfully initialized.
[ 2345.978509] mttcan c310000.mttcan can0: bitrate error 0.2%
[ 2345.978651] mttcan c310000.mttcan can0: Bitrate set
[ 2345.978725] mttcan_controller_config: ctrlmode 0
[ 2345.978743] mttcan c310000.mttcan can0: Bitrate set
[ 2345.979165] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 2349.818380] mcp251x spi2.0: failed to acquire irq 0

Hi Karis,
You do not have to add this code:
gpio@2200000 {
mcp2515_init {
gpio-hog;
input;
gpios = <TEGRA194_MAIN_GPIO(Y, 4) 0x1>;
label = “mcp2515_init”;
status = “okay”;
};
};
};

Just add below line also :
spi@3230000{
interrupt-parent = <&gpio>;
};

Hi shgarg,

I don’t understand what you mean.
is the dts right below? Thank you.

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

spi@3230000{ /* SPI3 in 40 pin conn */
spi@0 {
status = “okay”;
compatible = “microchip,mcp2515”;
reg = <0x0>;
spi-max-frequency = <10000000>;
nvidia,enable-hw-based-cs;
clocks = <&can_clock>;
interrupt-parent = <TEGRA194_MAIN_GPIO(Y, 4) 0x1;
};
};

Hi Karis,
Use this:
/ {
can_clock: can_clock {
compatible = “fixed-clock”;
#clock-cells = <0>;
clock-frequency = <20000000>;
clock-accuracy = <100>;
};

spi@3230000{ /* SPI3 in 40 pin conn */
spi@0 {
status = “okay”;
compatible = “microchip,mcp2515”;
reg = <0x0>;
spi-max-frequency = <10000000>;
nvidia,enable-hw-based-cs;
clocks = <&can_clock>;
interrupt-parent = <&tegra_main_gpio>;
interrupts = <TEGRA194_MAIN_GPIO(Y, 4) 0x1>;
};
};

Let me know if you face any issues.

Thanks,
Shubhi

Hi shgarg,

I got message below,and I didn’t receive any data from can port.

[   79.339795] mcp251x spi2.0 can1: MCP2515 successfully initialized.
[  122.112783] mttcan c310000.mttcan can0: bitrate error 0.2%
[  122.112937] mttcan c310000.mttcan can0: Bitrate set
[  145.201083] mttcan_controller_config: ctrlmode 0
[  145.201113] mttcan c310000.mttcan can0: Bitrate set
[  148.128321] gpio tegra-gpio wake58 for gpio=196(Y:4)
[  162.496923] mttcan c310000.mttcan can0: entered error warning state
[  162.497108] mttcan c310000.mttcan can0: entered error passive state
[  168.105332] mttcan c310000.mttcan can0: entered bus off state

CONFIG_CAN_RAW=y
CONFIG_CAN_GW=y
CONFIG_CAN_DEV=y
CONFIG_MTTCAN=y

My steps below:

  1. sudo insmod mcp251x.ko
  2. sudo ip link set can0 type can bitrate 500000
    sudo ip link set can1 type can bitrate 500000
  3. sudo ip link set can0 up
    sudo ip link set can1 up
  4. open two terminals.
    candump can0
    cansend can1 123#abcdabcd

Thank you!

Karis

Hi Karis,
Can you try wth only MCP via loopback to check if MCP is fine?
short SPI_MOSI and MISO
and use:sudo ip link set can0 type can bitrate 500000 loopback on
sudo ip link set can0 up
candump can0 &
cansend can0 123#abcdabcd

Let me know the results.

Hi shgarg,

I got data from can1.

By the way,can0 is another canbus port which has transceiver.

I have a problem below.
I didn’t short short SPI_MOSI and MISO,I used the loopback function,and I got data from can1.is it right?

Thank you!

Karis

Hi Karis,
Yes that is correct.
Sorry, as SPI on MCP, you do not need to short pins.
So MCP in fine on NX right?
Now, can0 is connected to NX CAN port via transceiver?

Hi shgarg,

So MCP in fine on NX right?

You mean can1 from mcp2515?

Now, can0 is connected to NX CAN port via transceiver?

Yes,if I use “ifconfig -a” command,I can see the can0.
I used two platforms( NX with our carrier board),that could send and receive data from two platforms.

Karis

Hi,
I am still confused with the setup.
NX has SPI and CAN both.
On SPI, you have connected CAN1 which is working fine on loopback.
The other CAN0, how it is connected? Is it connected to the CAN port of Jetson-NX? From CAN0 port of NX, you have connected transceiver then?

Hi shgarg,

NX has SPI and CAN both.

Our carrier board has one can port,and one SPI port.
CAN:connect to NX canbus port.
can0(connect transceiver at our carrier board).
SPI : connect to NX spi port.
Use mcp2515(can1)

Does can0 send data to can1?

Hi Karis,
Thanks for the info.
We have not yet varied this setup (MTTCAN with MCP251x). And now as we do not have physical access to the board, it may take time to fix your problem.

Hi shgarg,

How to test the only canbus port?
I would like to know the canbus port (HW) is work fine,which is connect transceiver.

Thank you!

Karis

Hi,
Short pins on transceiver: CAN_TX and CAN_RX
No need to connect CAN_H and CAN_L anywhere for loopback.
try same above loopback commands.

Hi shgarg,

Thanks for your reply!

For test function is fine,but is not for production.

Karis