Enabling spidev on the jetson nano is hanging when flashing

Hi @JohnWCreate, @devemin,

Finally, I found the way to use SPI1(Pin 19, 21, 23, 24).
The new version of dts is publised here:
https://github.com/rt-net/JetsonNano_DT_SPI
You just need is to run the scrpit as before.

The differences between previous one and present one can be seen from here:
https://github.com/rt-net/JetsonNano_DT_SPI/commit/0124b15ea6e29a0a45246223b7c892aa39e20678

Accroding to “Jetson Nano Product Design Guide” which was published on June 10th, 2019, SPI1(Pin 19, 21, 23, 24) is connected to SPI0 on Tegra X1, not SPI1.
This caused the problem. We need to use “/dev/spidev0.0” instead of “/dev/spidev1.0”.
“Jetson Nano Product Design Guide” is available from here:
https://developer.nvidia.com/embedded/dlc/jetson-nano-product-design-guide

I tested the SPI loopback code posted here.
https://importgeek.wordpress.com/2017/09/11/raspberry-pi-spi-loopback-testing/

$ ./spidev_test -D /dev/spidev0.0
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF 
40 00 00 00 00 95 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
FF FF FF FF FF FF 
DE AD BE EF BA AD 
F0 0D

I hope this helps.

Hi tiryoh!
Woo! Great!
You fixed my problem!

I got successful results with spidev_test loopback test.
(I connected between MISO and MOSI.)

Next, I am trying to use a few SPI devices now.

My SPI device [ADT7310, temp sensor IN & OUT] is working good.

[mcp3204, AD-con IN & OUT] got unstable results.

[Max31855, temp sensor OUT only] is not working.

[AQM1248A, LCD IN only] is checking now.

I will try to confirm about pin’s pulse, pull-up or pull-down settings, difference of raspberry pi’s settings, and test codes of course.

If there is proress, I will show reports about my SPI devices.

Thanks!

devemin

I’m currently looking for some spidev C++ examples, would anyone share some code (maybe @devemin)?

Which library are you using with spidev?

I’ve found the following two and haven’t been able to get them to work yet.

https://github.com/KoynovStas/Linux_SPI

https://github.com/vsergeev/c-periphery

Thanks!

-Phil

hello Phil_L.

I use this blog’s code without libraries, with direct accessing to /dev/spidev*.* .

MAX31855A ( C , not working)
https://blog.goo.ne.jp/lm324/e/24b10f98d1b335feae90673fa89eeeff

ADT7310( Python py-spidev , working)
https://www.denshi.club/pc/raspi/5raspberry-pi-zeroiot14-i2c-adt7410.html

thanks.

devemin

Hello there !

The solutions detailed in this thread doesn’t work anymore on Jetpack 4.2.1 …
The spidev is indeed enabled but the GPIO pinmux remains unchanged this time, even with the modifications on the gpio@6000d000 entry (see the screenshot attached)

How can we map the correct GPIO as SFIO again ?

Thanks,
Kamel

Hi Kamel,

Did you solved it? I got the same problem

Hello Pawel,

No, I gave up ! Still waiting for an official Nvidia update …

Good luck,

Hi KmL_, pawel.zabielowicz,

Same issue here.
I’m using Jetpack 4.2 included with L4T 32.1 instead of Jetpack 4.2.1 or 4.2.2.
The way to enable SPI works on Jetpack 4.2 + L4T 32.1.

Hi All
J4.2.1 have regression for this feature.
Please apply below patch to try.

diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index e1010440f32d..09dd6e4a8698 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -217,6 +217,11 @@ static void tegra_gpio_enable(struct tegra_gpio_info *tgi, int gpio)
        tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 1);
 }
 
+static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio)
+{
+       tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 0);
+}
+
 static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset)
 {
        tegra_gpio_save_gpio_state(offset);
@@ -225,8 +230,12 @@ static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset)
 
 static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)
 {
+       struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
+
        pinctrl_free_gpio(chip->base + offset);
        tegra_gpio_restore_gpio_state(offset);
+       tegra_gpio_disable(tgi, offset);
+
 }
 
 static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)

Just FYI… You have to replace the leading spaces in that patch with tabs before you apply or it will fail.

Is there anyone who managed to enable SPI with JetPack4.2.2?

I first followed https://github.com/rt-net/JetsonNano_DT_SPI from triyoh, but this didn’t work for me.

Hi @jtktchinou,

The scripts for L4T R32.2.1 is published here:
https://github.com/rt-net/JetsonNano_DT_SPI/tree/R32.2.1

It has only tested on a few environments, so it may contain bugs.
I would appreciate it if you could test the script and report the results.

Thank you for the responce @triyoh,

I couldn’t finish the process this time, I got a downloading error following:

test@TEST:~/JetsonNano_DT_SPI$ ./run.sh
[sudo] password for test: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
device-tree-compiler is already the newest version (1.4.5-3).
lbzip2 is already the newest version (2.5-2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
--2019-11-12 16:58:55--  https://developer.nvidia.com/embedded/dlc/Jetson-210_Linux_R32.2.1
Resolving developer.nvidia.com (developer.nvidia.com)... 192.229.189.146
Connecting to developer.nvidia.com (developer.nvidia.com)|192.229.189.146|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://developer.download.nvidia.com/embedded/L4T/r32-2-1_Release_v1.0/Nano-TX1/Jetson-210_Linux_R32.2.1_aarch64.tbz2?1wChwbIpuqOqZLrfioD3H4gLd97N6forkMo0yTp1FSz-T_gq_u1CJd_mSHALoLkPdASFSW85B7DLb7OcVnAqQir14bJbhWnSWvBQcT-cLtaOm6Vhueaa8r_accKPPOi6K6DWgBaR2fWc3rxFWTgx55gpH9TMyFYlNnHwZmBqtXAVdu8Q1nN8zQN-_A1m2LM [following]
--2019-11-12 16:58:56--  https://developer.download.nvidia.com/embedded/L4T/r32-2-1_Release_v1.0/Nano-TX1/Jetson-210_Linux_R32.2.1_aarch64.tbz2?1wChwbIpuqOqZLrfioD3H4gLd97N6forkMo0yTp1FSz-T_gq_u1CJd_mSHALoLkPdASFSW85B7DLb7OcVnAqQir14bJbhWnSWvBQcT-cLtaOm6Vhueaa8r_accKPPOi6K6DWgBaR2fWc3rxFWTgx55gpH9TMyFYlNnHwZmBqtXAVdu8Q1nN8zQN-_A1m2LM
Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 192.229.232.112
Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|192.229.232.112|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 195896637 (187M) [application/octet-stream]
Saving to: ‘Jetson-Nano-Tegra210_Linux_R32.2.1_aarch64.tbz2’

Jetson-Nano-Tegra21 100%[===================>] 186.82M  6.97MB/s    in 20s     

2019-11-12 16:59:16 (9.25 MB/s) - ‘Jetson-Nano-Tegra210_Linux_R32.2.1_aarch64.tbz2’ saved [195896637/195896637]

--2019-11-12 16:59:16--  https://developer.nvidia.com/embedded/dlc/r32-2-1_Release_v1.0/Nano-TX1/Tegra_Linux_Sample-Root-Filesystem_R32.2.1_aarch64.tbz2
Resolving developer.nvidia.com (developer.nvidia.com)... 192.229.189.146
Connecting to developer.nvidia.com (developer.nvidia.com)|192.229.189.146|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://developer.download.nvidia.com/embedded/L4T/r32-2-1_Release_v1.0/Nano-TX1/Tegra_Linux_Sample-Root-Filesystem_R32.2.1_aarch64.tbz2?hWrbXqYu34IHPtL_qhk1PCll8mzB0JD25xYX5AugA5DGw3yi3iz7wLyY1zcmSSg7piWo1EJlycyfsM5lPXMICx0CpGY3X7OZe_SU2dzitkQkupPWgdq4IT-0mljcjmy-r22S9Rkplac0_A6iw-H1O7A8bdktFw8DrdAecpOl1aWfO480y1zOzeSsmXZBx5DRA8rEd-HQUzInxGY7B5s2L4c [following]
--2019-11-12 16:59:17--  https://developer.download.nvidia.com/embedded/L4T/r32-2-1_Release_v1.0/Nano-TX1/Tegra_Linux_Sample-Root-Filesystem_R32.2.1_aarch64.tbz2?hWrbXqYu34IHPtL_qhk1PCll8mzB0JD25xYX5AugA5DGw3yi3iz7wLyY1zcmSSg7piWo1EJlycyfsM5lPXMICx0CpGY3X7OZe_SU2dzitkQkupPWgdq4IT-0mljcjmy-r22S9Rkplac0_A6iw-H1O7A8bdktFw8DrdAecpOl1aWfO480y1zOzeSsmXZBx5DRA8rEd-HQUzInxGY7B5s2L4c
Resolving developer.download.nvidia.com (developer.download.nvidia.com)... 192.229.232.112
Connecting to developer.download.nvidia.com (developer.download.nvidia.com)|192.229.232.112|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1269846354 (1.2G) [application/octet-stream]
Saving to: ‘Jetson-Nano-Tegra_Linux_Sample-Root-Filesystem_R32.2.1_aarch64.tbz2’

Jetson-Nano-Tegra_L 100%[===================>]   1.18G  8.45MB/s    in 2m 1s   

2019-11-12 17:01:20 (9.97 MB/s) - ‘Jetson-Nano-Tegra_Linux_Sample-Root-Filesystem_R32.2.1_aarch64.tbz2’ saved [1269846354/1269846354]

Jetson-Nano-Tegra210_Linux_R32.2.1_aarch64.tbz2: FAILED
Jetson-Nano-Tegra_Linux_Sample-Root-Filesystem_R32.2.1_aarch64.tbz2: OK
md5sum: WARNING: 1 computed checksum did NOT match
File download error.

It seems “Jetson-Nano-Tegra210_Linux_R32.2.1_aarch64.tbz2” has been downloaded without any error, but has some problems inside? Any idea to fix this?
I will bypass the md5sum to check others are ok.

I used a just flashed JetPack4.2.2, since the former environment has been corrupted.

I finally managed to enable SPI with JetPack4.2.2.
I just skipped “md5sum -c $SRC_DIR/MD5SUM || { echo File download error.; exit 1; }” in line 13 of “run.sh”.

Thanks @triyoh!

could anybody share a JetPack4.2.2 SD card image with SPI enabled as it should be? thanks in advance.
it is frustrating all over that we need to do this for a feature that’s supposed to work out of the box via the expander connector.

flashing fails continuously on my end and wouldn’t spend another minute trying to ‘fix’ this via flashing.

Thanks for your feedback, @jtktchinou!
I added an issue here: https://github.com/rt-net/JetsonNano_DT_SPI/issues/6

this doesn’t work for me:
root@jetson:/home/jetson# sudo cat /sys/kernel/debug/tegra_gpio
Name:Bank:Port CNF OE OUT IN INT_STA INT_ENB INT_LVL
A: 0:0 64 40 40 24 00 00 000000
B: 0:1 f0 00 00 00 00 00 000000
C: 0:2 1f 00 00 00 00 00 000000

root@jetson:/home/jetson# ls -la /dev/spi*
crw------- 1 root root 153, 0 Nov 13 08:48 /dev/spidev0.0

jetson@jetson:~/Work/spi$ sudo ./spidev_test -D /dev/spidev0.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
jetson@jetson:~/Work/spi$


looking at the GPIO pins, it doesn’t seem that they are updated for use with SPI so that explains the behavior.

@tiryoh
I started over and have a different behavior but still no function:
root@jetson:/home/jetson# cat /sys/kernel/debug/tegra_gpio
Name:Bank:Port CNF OE OUT IN INT_STA INT_ENB INT_LVL
A: 0:0 64 40 40 04 00 00 000000
B: 0:1 f0 00 00 00 00 00 000000
C: 0:2 00 00 00 00 00 00 000000
D: 0:3 00 00 00 00 00 00 000000

root@jetson:/home/jetson# ls /dev/spi*
/dev/spidev0.0
root@jetson:/home/jetson# dmesg | grep spi
[ 0.439710] iommu: Adding device 7000d400.spi to group 7
[ 0.439969] iommu: Adding device 7000d600.spi to group 8
[ 0.440238] iommu: Adding device 70410000.spi to group 9
[ 1.076962] tegra-qspi 70410000.spi: Prod settings list not found
[ 1.078294] qspi_mtd spi32766.0: MX25U3235F (4096 Kbytes)
[ 1.078304] qspi_mtd spi32766.0: mtd .name = spi32766.0, .size = 0x400000 (4MiB) .erasesize = 0x00001000 (4KiB) .numeraseregions = 0

root@jetson:/home/jetson/Work/spi# ./spidev_test -D /dev/spidev0.0
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
root@jetson:/home/jetson/Work/spi#

it seems I have a working loopback mode:
jetson@jetson:~/Work/spi$ sudo ./spidev_test -D /dev/spidev0.0 -v -p “1234abcd”
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
TX | 31 32 33 34 61 62 63 64 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ |1234abcd|
RX | 31 32 33 34 61 62 63 64 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ |1234abcd|

the -v option is required in my case, otherwise I don’t see what’s happening.

I ended here after running the entire script which updated all required partitions. updating only DTB partition is not enough on fresh install.