The MCP2515 CAN module is currently not officially supported on the Jetson Nano 2GB and does not work out of the box using the current Jetpack 46. This might change in the future. I have only tested this with this 16MHz can module by JOY-IT. For 8MHz can modules you have to change the can clock in the .dts file.
1. Wiring
Wire the two can modules to the 40pin header according to this table.
Name | CAN module 1 | CAN module 2 |
---|---|---|
INT | 31 | 32 |
SCK | 23 | 13 |
SI | 19 | 37 |
SO | 22 | 21 |
CS | 24 | 18 |
GND | GND | GND |
VCC1 | 5V | 5V |
VCC | 3V3 | 3V3 |
2. Download Nvidia Jetson Driver Package
Download the Nvidia Jetson Driver Package ( L4T Driver Package (BSP) Sources for the Jetson Nano 2GB) from here: https://developer.nvidia.com/embedded/linux-tegra
Extract it to a folder of your choosing. Then extract on the Jetson Nano “kernel_src.tbz2” to a folder. We will refer to this folder as later. Everything following will be done on the Jetson Nano.
3. Copy .dts file
I modified the device tree file from Thor-x86 on this thread. You can download it here:
jetson-mcp251x.dts (3.8 KB)
Back up the existing jetson-mcp251x.dts in /hardware/nvidia/platform/t210/tegra/common/kernel-dts/overlays. After that copy the downloaded .dts file to /hardware/nvidia/platform/t210/tegra/common/kernel-dts/overlays
4. Build Device Tree overlay
In the Terminal go to /kernel/kernel-4.9. Then run:
> make ARCH=arm64 tegra_defconfig
> make ARCH=arm64 dtbs
> sudo cp arch/arm64/boot/dts/tegra210-p3348-0003-p3542-0000-mcp251x.dtbo /boot
This will build the device tree overlay and copy it to the /boot folder.
5. Run Jetson-IO
The device tree overlay can be applied using the jetson-io tool. For that run:
> sudo /opt/nvidia/jetson-io/jetson-io.py
Select Configure Jetson 40pin Header
Select Configure for compatible hardware
Select MCP251x CAN Controller
Select Save pin changes
Select Save and reboot to reconfigure pins
The Jetson Nano will reboot and everything should work.
Fixing Jetson-IO
Jetson-IO seems to be broken on new installations at the moment. If it only quickly flashes on the screen and immediately closes do the following:
In the Terminal run:
> sudo gedit /opt/nvidia/jetson-io/Jetson/board.py
The Text Editor should open. Find the line:
dtbdir = os.path.join(self.bootdir, 'dtb')
and change it to
dtbdir = os.path.join(self.bootdir, '')
(6. Update the driver)
I don’t know, if this is still necessary with the latest Jetpack, but if the device tree overlay was not enough to get things working you can try this.
Backup the existing mcp251x.c in /kernel/kernel-4.9/drivers/net/can/spi/. Then copy the
mcp251x.c (33.6 KB) file to /kernel/kernel-4.9/drivers/net/can/spi/
In the Terminal go to /kernel/kernel-4.9. Then run:
> ./nvbuild.sh
If you have not build the kernel before, this will take about an hour.
After that run
> sudo cp <kernel-source>/kernel/kernel-4.9/drivers/net/can/spi/mcp251x.ko /lib/modules/4.9.253-tegra/kernel/drivers/net/can/spi
> insmod /lib/modules/4.9.253-tegra/kernel/drivers/net/can/spi
> sudo modprobe mcp251x
to copy and load the driver file. Then reboot to reload driver an reinitialize can modules
You can test if the device tree overlay and the driver work by running
> dmesg | grep spi
The output should look similar to this.
[ 0.417489] iommu: Adding device 7000d400.spi to group 7
[ 0.417784] iommu: Adding device 7000d600.spi to group 8
[ 0.418052] iommu: Adding device 70410000.spi to group 9
[ 1.100047] tegra-qspi 70410000.spi: Prod settings list not found
[ 1.101202] qspi_mtd spi32766.0: MX25U3235F (4096 Kbytes)
[ 1.101212] qspi_mtd spi32766.0: mtd .name = spi32766.0, .size = 0x400000 (4MiB) .erasesize = 0x00001000 (4KiB) .numeraseregions = 0
[ 3.661687] mcp251x spi0.0: aquired IRQ: 297
[ 3.680364] mcp251x spi0.0 can0: MCP2515 successfully initialized.
[ 3.680736] mcp251x spi1.0: aquired IRQ: 265
[ 3.698902] mcp251x spi1.0 can1: MCP2515 successfully initialized.
7. Use the CAN Interfaces
You can bring up a can interface by running:
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
With
candump -x any
you can view incoming can messages while
cansend can0 456#deadbeef
can be used to send can messages.
Thanks to these users for sharing their work, which enabled me to get this working.
Thor-x86 BUG: Jetson Nano P3450-B00 with MCP2515, can receive but cannot send
noloda3040 JetPack 4.3 - L4T R32.3.1 released - #13 by noloda3040