Difference between revisions of "Jetson/TX2 SPI"

From eLinux.org
Jump to: navigation, search
(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...")
 
m
Line 1: Line 1:
 
This how-to enables SPI in the kernel for [[Jetson_TX2|Jetson TX2]] with L4T R28.1 (JetPack 3.1).  For the previous version see, [[Jetson/TX1 SPI]].
 
This how-to enables SPI in the kernel for [[Jetson_TX2|Jetson TX2]] with L4T R28.1 (JetPack 3.1).  For the previous version see, [[Jetson/TX1 SPI]].
  
See the original DevTalk discussion thread here: https://devtalk.nvidia.com/default/topic/1024806/how-to-enable-spi-spidev-on-28-1-on-target-/
+
{| style="color: black; background-color: #ffffff; width: 825px;"
 +
|-
 +
| style="width: 5px; background-color: white;"|
 +
| style="width: 820px; background-color: #999999;"|
 +
{{spaces|1}} <span style="font-family: Trebuchet MS; color: white;">'''DevTalk Thread''' — see </span>''[https://devtalk.nvidia.com/default/topic/1024806/how-to-enable-spi-spidev-on-28-1-on-target-/ <span style="font-family: Trebuchet MS; color:white;">https://devtalk.nvidia.com/default/topic/1024806/how-to-enable-spi-spidev-on-28-1-on-target-/</span>]''
 +
|}
 +
<br />
  
 
== Locating the SPI Pins ==
 
== Locating the SPI Pins ==

Revision as of 08:03, 4 December 2017

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.

  DevTalk Thread — see https://devtalk.nvidia.com/default/topic/1024806/how-to-enable-spi-spidev-on-28-1-on-target-/


Locating the SPI Pins

First, in the Jetson TX2 Developer Kit, the SPI pins are located 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

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: https://developer.nvidia.com/embedded/dlc/l4t-sources-28-1

JetsonHacks also has a script (https://github.com/jetsonhacks/buildJetsonTX2Kernel)

 $ git clone http://github.com/jetsonhacks/buildJetsonTX2Kernel.git
 $ cd buildJetsonTX2Kernel
 $ ./getKernelSources.sh

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

 CONFIG_SPI=y
 CONFIG_SPI_TEGRA114=y
 CONFIG_SPI_SPIDEV=m
 CONFIG_QSPI_TEGRA186=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 ./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/

Update module dependencies and kernel image:

 $ sudo depmod
 $ sudo ./copyImage.sh

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:

 spi@3240000{
    compatible = "nvidia,tegra186-spi";
    reg = <0x0 0x3240000 0x0 0x10000>;
    ....
    ....
    ....
    linux,phandle = <0x80>;
    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>;
    }; 
 };

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

 TIMEOUT 30
 DEFAULT PRIMARY
 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