Hi, guys.
I’ve had several private messages with people asking me how to get SPI working on the TX2 using 28.1. I can easily understand why people struggle given the changes to 27.1 and 28.1. I feel the guides referring to the enabling SPI (https://elinux.org/Jetson/TX1_SPI) are no longer valid anymore.
I’d like to give a shoutout to JetsonHacks(http://www.jetsonhacks.com) and LinuxDev for their indirect help towards this post.
Guide for (on-target) enabling SPI / SPIDev on the Jetson TX2:
Wheres the SPI Pins?
On the J21 header: http://www.jetsonhacks.com/nvidia-jetson-tx2-j21-header-pinout/
- Pin 19 - SPI(3) MOSI
- Pin 21 - SPI(3) MISO
- Pin 23 - SPI(3) CLK
- Pin 24 - SPI(3) CS#0
Get the kernel sources
I recommend Jetsonhacks (https://github.com/jetsonhacks/buildJetsonTX2Kernel)
$ git clone http://github.com/jetsonhacks/buildJetsonTX2Kernel.git
$ cd buildJetsonTX2Kernel
$ ./getKernelSources.sh
An application will come up (xconfig), I generally ignore this (close) as I usually build on a host machine.
The JetsonHacks script should have downloaded the kernel sources to the /usr/src/ folder, I suggest adding ‘SPIDEV’ to the tegra18_def_config file
$ cd /usr/src
$ cd /kernel/kernel-4.4/
$ cd /arch/arm64/configs/
$ sudo gedit tegra18_defconfig
Add the following to just below ‘CONFIG_SPI_TEGRA114_SPI=y’
CONFIG_SPI=y
CONFIG_SPI_TEGRA114=y
<b>CONFIG_SPI_SPIDEV=m</b>
CONFIG_QSPI_TEGRA186=y
Build the kernel
Get your .conf file
$ cd /usr/src/kernel/kernel-4.4
$ sudo make tegra18_defconfig
$ cd ~/GIT/buildJetsonTX2Kernel
$ sudo ./makeKernel.sh
//Ensure the SPIDev Kernel module is copied to /lib/modules...
$ sudo cp /usr/src/kernel/kernel-4.4/drivers/spi/spidev.ko /lib/modules/$(uname -r)/kernel/drivers/
// Module dependencies
$ sudo depmod
$ sudo ./copyImage.sh
// Reboot
$ sudo reboot
Once the Jetson has rebooted, navigate to /lib/modules/$(uname -r)
$ cd /lib/modules/$(uname -r)
$ cat modules.dep
// print the contents of modules.dep to the screen, and ensure spidev.ko is in there
// e.g. @line 23
//kernel/drivers/spi/spidev.ko
Modify Device-Tree
I generally build on a host machine, and find its easier. But some people might need to modify the device tree on the device itself. Since 28.1 FDT has been taken out of the extlinux.conf file in /boot/extlinux/
First we need the device-tree-compiler
$ sudo apt-get update
$ sudo apt-get install device-tree-compiler
Decompile Device-Tree
$ cd /boot/dtb/
$ sudo dtc -I dtb -O dts -o myTX2DeviceTreeSource.dts tegra186-quill-p3310-1000-c03-00-base.dtb
Update The Device-Tree
$ sudo gedit myTX2DeviceTreeSource.dts
spi@3240000{
compatible = "nvidia,tegra186-spi";
reg = <0x0 0x3240000 0x0 0x10000>;
....
....
....
linux,phandle = <0x80>;
[b]spi@0 {
compatible = "spidev";
reg = <0x0>;
spi-max-frequency = <0x1312D00>;
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-delau = <0x0>;
};
[/b]
};
Recompile The Device-Tree
$ cd /boot/dtb/
$ sudo dtc -I dts -O dtb -o tegra186-quill-p3310-1000-c03-00-base.dtb myTX2DeviceTreeSource.dts
Add /boot/dtb/ to FDT
Since 27.1 FDT has been removed from extlinux.conf (this is where this step falls over https://elinux.org/Jetson/TX1_SPI#Booting_with_the_New_DTB)
$ cd /boot/extlinux/
$ sudo gedit extlinux.conf
Add the FDT line to your extlinux.conf file
TIMEOUT 30
DEFAULT PRIMARY
MENU TITLE p2771-0000 eMMC boot options
LABEL primary
MENU LABEL primary kernel
LINUX /boot/Image
<b>FDT /boot/dtb/tegra186-quill-p3310-1000-c03-00-base.dtb</b>
APPEND ${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4
That should be it… Reboot for things to take effect
$ sudo reboot
Check if Spidev is available in your /dev/ folder
$ ls /dev/spi*
$ /dev/spidev.3.0
This method is by no means perfect, it’s more of a bodge if anything, but hopefully it should let you add SPI without using a host machine. I will try make this post a bit more cleaner in the coming days, but I think it’s necessary to have a more up-to-date guide on adding SPI to the TX2.