Jetson Nano SPI C/C++ Example

Has Nvidia implemented SPI for the Jetson Nano using C or C++? I have many applications for this.

1 Like

Not sure what you really want to get but you can reference to the spi_test.c from the kernel test source code.

1 Like

When I found the Jetson Nano, what motivated me to buy it was the 128-core CPU, the artificial intelligence philosophy, and the “40-pin expansion header with GPIO, I2C, I2S, SPI, UART signals”.

I need SPI to communicate with many devices such as, IMU sensors, TFT LCD, ADC chip, etc. Certain threads claim that SPI is not enabled. If this is so, how can it be activated, and is there a working C or C++ example sanctioned by Nvidia? I could not find your “spi_test.c”.

So far, I got the UART working on J41 using C++. This was huge. Also found fast Direct Register Access GPIO using C++, but it only works on a handful of pins. SPI is the next big need. I’d like to buy more Nanos, but I’m spending most of my time getting basic peripherals to work that should already be working. It’s a bit disappointing. That said, I have high hopes for the Nano - the potential is way beyond the R-Pi. From a business perspective, I think Nvidia will find more customers if they aim not only the artificial intelligence people, but also aim for the huge Arduino and Teensy community and maker community.

2 Likes

For the J4.2.2 you can follow below link to enable the SPI. After r32.3 release you don’t need to update bootloader to enable SPI.

The spi_test.c is public kernel source.

What linux command can I use to check which release version I have? I bought my Nano back in July, 2019.

If you haven’t upgraded it, it’s probably an early 32.2. 32.3 hasn’t been released yet.

32.3 will coming soon.

Is there a top-level list of updates for 32.3?

For the SPI on r32.3 you don’t need to modify the pinmux at bootloader. However if you can’t wait you can have below reference to enable it on current version.

I see that R32.2.3 is available as of 12/11/2019. Is this considered the latest, or is R32.3 (with SPI enabled) the next version? To be released when?

Hi ShaneCCC,

My l4t version is the lastest version r32.3, how can I check SPIs are enabled or not. I found no SPI devices in /proc/devices and /dev/.

isbu:/boot/dtb$ head /etc/nv_tegra_release
# R32 (release), REVISION: 2.3, GCID: 17644089, BOARD: t210ref, EABI: aarch64, DATE: Tue Nov  5 21:56:03 UTC 2019
isbu:/boot/dtb$ cat /proc/devices | grep -i spi
isbu:/boot/dtb$ ls /dev/ | grep -i spi

Thanks

You still need to modify the device tree to enable the SPI.

Hi ShaneCCC,

I use the dtb file in jetson-nano-support. But it not work.

isbu:/boot/dtb$ head /etc/nv_tegra_release
# R32 (release), REVISION: 2.3, GCID: 17644089, BOARD: t210ref, EABI: aarch64, DATE: Tue Nov  5 21:56:03 UTC 2019

Didn’t see the /dev/spidevx.x ?

1 Like

Hi ShaneCCC,

I am clearly sure there is no SPI node under /dev/ directory and any device in /proc/devices. And gpioinfo show the SPIs are unused.

gpioinfo: error accessing GPIO chips: Permission denied
isbu:~$ sudo gpioinfo | grep -i spi
[sudo] password for isbu:
        line  12:  "SPI1_MOSI"       unused   input  active-high
        line  13:  "SPI1_MISO"       unused   input  active-high
        line  14:   "SPI1_SCK"       unused   input  active-high
        line  15:   "SPI1_CS0"       unused   input  active-high
        line  16:  "SPI0_MOSI"       unused   input  active-high
        line  17:  "SPI0_MISO"       unused   input  active-high
        line  18:   "SPI0_SCK"       unused   input  active-high
        line  19:   "SPI0_CS0"       unused   input  active-high
        line  20:   "SPI0_CS1"       unused   input  active-high
        line 232:   "SPI1_CS1"       unused   input  active-high

isbu:~$ cat /proc/devices | grep -i spi
isbu:~$ ls /dev/ | grep -i spi
1 Like

That could be your dt not update well. Have a check the extracted_proc.dts that include the context that you add.

$ sudo apt-get update
$ sudo apt-get install device-tree-compiler
$ cd /boot/dtb/
$ sudo dtc -I fs -O dts -o extracted_proc.dts /proc/device-tree

Hi ShaneCCC,

Thanks

It seems that the way through copying a dtb to /boot/dtb directly doesn’t work. But don’t know why the extracted_proc.dts generated by “sudo dtc -I fs -O dts -o extracted_proc.dts /proc/device-tree” not the same as that tegra210-p3448-0000-p3449-0000-a02-spidev-0.dts.

MD5:

isbu:~$ md5sum tegra210-p3448-0000-p3449-0000-a02-spidev-0.dtb
0435df49e809d3fc6de63722cd53bd74  tegra210-p3448-0000-p3449-0000-a02-spidev-0.dtb
isbu:~$ md5sum /boot/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb
0435df49e809d3fc6de63722cd53bd74  /boot/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb

And spi1_mosi_pc0 node in extracted_proc.dts

spi1_mosi_pc0 {
				nvidia,enable-input = <0x1>;
				nvidia,pins = "spi1_mosi_pc0";
				nvidia,tristate = <0x0>;
				nvidia,function = "rsvd1";
				nvidia,pull = <0x1>;
			};

which should be the same as blow in tegra210-p3448-0000-p3449-0000-a02-spidev-0.dts.

spi1_mosi_pc0 {
                                nvidia,pins = "spi1_mosi_pc0";
                                nvidia,function = "spi1";
                                nvidia,pull = <0x1>;
                                nvidia,tristate = <0x0>;
                                nvidia,enable-input = <0x1>;
                        };

extracted_proc.dts.txt (282 KB)

1 Like

Hi ShaneCCC,

I use “sudo ./flash.sh -r jetson-nano-qspi-sd mmcblk0p1” script, and it works. So that the dtb and uboot have no problem.

Hi ShaneCCC,

Sorry for my mistake, the dtb in /boot/dtb/ are actually not used when the board runs. So I have to flash the target dtb file to the DTB partition detailed in In-system update of DTB in R28.2.

Thanks

Trying, like others, to activate SPI. I’ve just put a new sd image 32.3.1 on a Nano. With it I see two spi devices in /dev : spidev0.0 and 1.0, but no joy with spidev_test - always recieves zeros (MOSI, MISO pins bridged). I tried to use jetson-io.py to set things up, but the terminal screen immediately closes - can’t even grab the error. I then try one of the other python scripts, for example config-by-hardware and it tells me there is no DTB found found for NVIDIA Jetson Nano Developer Kit - probably the reason jetson-io is closing so fast. Any ideas out there will be much appreciated.