Jetson/TX2 SPI

< Jetson
Revision as of 07:51, 4 December 2017 by Dusty-nv (talk | contribs) (Created page with "This how-to enables SPI in the kernel for Jetson TX2 with L4T R28.1 (JetPack 3.1). For the previous version see, Jetson/TX1 SPI. See the original DevTalk...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This how-to enables SPI in the kernel for Jetson TX2 with L4T R28.1 (JetPack 3.1). For the previous version see, Jetson/TX1 SPI.

See the original DevTalk discussion thread here:

Locating the SPI Pins

First, in the Jetson TX2 Developer Kit, the SPI pins are located on the J21 header -

  • Pin 19 - SPI(3) MOSI
  • Pin 21 - SPI(3) MISO
  • Pin 23 - SPI(3) CLK
  • Pin 24 - SPI(3) CS#0

Building SPIDev Module

It's suggested to enable support for SPIDev (userspace API).

To do that, we'll download the L4T kernel sources, enable SPIDev module in the kernel configuration, build and install the module.

Downloading the Kernel Sources

L4T source tarball available here:

JetsonHacks also has a script (

 $ git clone
 $ cd buildJetsonTX2Kernel
 $ ./

The JetsonHacks script should have downloaded the kernel sources to the /usr/src/ folder.

Configuring the Kernel

Edit the tegra18_defconfig 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


Building the Kernel

Generate the new .conf file after the changes to tegra18_defconfig

 $ cd /usr/src/kernel/kernel-4.4
 $ sudo make tegra18_defconfig

Build the kernel modules:

 $ cd ~/buildJetsonTX2Kernel 
 $ sudo ./

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/

Update module dependencies and kernel image:

 $ sudo depmod
 $ sudo ./

Reboot to new config:

 $ sudo reboot

Verifying SPIDev Module

To verify the SPIDev kernel module that we built is enabled, 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

Modifying the Device Tree

Next, we must enable the SPI device in the Jetson's device tree.

To do this, we'll install the device tree compiler (DTC), modify the device tree source (DTS), and re-build the device tree binary (DTB).

Installing DTC Tool

First we need the device-tree-compiler

 $ sudo apt-get update
 $ sudo apt-get install device-tree-compiler

Decompiling Device Tree

To obtain the device tree source (DTS) that we'll edit, first we need to decompile the current device tree binary (DTB) back to source:

 $ cd /boot/dtb/
 $ sudo dtc -I dtb -O dts -o myTX2DeviceTreeSource.dts tegra186-quill-p3310-1000-c03-00-base.dtb

Update The Device-Tree

Use your text editor of choice to update the DTS that we decompiled above:

 $ sudo gedit myTX2DeviceTreeSource.dts

Make the following patches:

    compatible = "nvidia,tegra186-spi";
    reg = <0x0 0x3240000 0x0 0x10000>;
    linux,phandle = <0x80>;
    spi@0 {
      compatible = "spidev";
      reg = <0x0>;
      spi-max-frequency = <0x1312D00>;
      nvidia,cs-setup-clk-count = <0x1e>;
      nvidia,cs-hold-clk-count = <0x1e>;
      nvidia,rx-clk-tap-delay = <0x1f>;
      nvidia,tx-clk-tap-delau = <0x0>;

Recompiling the Device Tree

Use DTC again to recompile the modifying DTS back into the new DTB:

 $ cd /boot/dtb/
 $ sudo dtc -I dts -O dtb -o tegra186-quill-p3310-1000-c03-00-base.dtb myTX2DeviceTreeSource.dts

Enabling the New DTB

As in Jetson/TX2 DTB, enable FDT in /boot/extlinux.conf

 MENU TITLE p2771-0000 eMMC boot options
 LABEL primary
     MENU LABEL primary kernel
     LINUX /boot/Image
     FDT /boot/dtb/tegra186-quill-p3310-1000-c03-00-base.dtb
     APPEND ${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4

Reboot for the changes to take effect:

 $ sudo reboot

Verifying SPIDev Device

To confirm the SPIDev module has loaded and created the SPI device, check if SPIdev is available in your /dev folder:

 $ ls /dev/spi*
 $ /dev/spidev.3.0