Problem running the test for SPI

I managed to get spi3.0 device detected and now i am testing it based on the elinux documentation i was asked to follow

But the doc is terrible

in a copy of the kernel sources, change directories to tools/spi/
run CROSS_COMPILE= make
this requires an aarch64 (arm64) compatible gcc to be installed
Ex: sudo apt install gcc-aarch64-linux-gnu; CROSS_COMPILE=/usr/bin/aarch64-linux-gnu- make
copy the resulting spidev_test binary to the target system
Run spidev_test -D /dev/spidev3.0

What does this mean? Where is kernel sources?? I was told on the TX2 r32 i dont need the kernel files so how do i test this?

Is there a clear method to test SPI maybe using python? If yes, where is that example?

For the python http://domoticx.com/python-library-spidev/
For the tools/spi it’s in the kernel source. Please reference to l4t document to get it.
[url]Welcome — Jetson Linux<br/>Developer Guide 34.1 documentation

I read this document but I still cannot understand why the pinmux did not do anything.

I’m lost, please help!

I followed the pinmux tutorial on the elinux site but I am stuck as to what package to use to access SPI interface and also
An example code in python

I will check the domotix link in the morning

Also according to the change I made to the pinmux, is that correct at least?
Thanks a lot!

I agree 100%. I used the Nvidia SDK Manager (https://developer.nvidia.com/nvidia-sdk-manager) to setup the Jetson TX2. I, like many others, are finding it difficult to simply enable SPI. The doc which seems to be the one everyone points to (https://elinux.org/Jetson/TX2_SPI) could be significantly improved!!

I’ve spent the last few days trying to get it working and I think I reached the point where I need to test it. See my progress here for TX2 https://devtalk.nvidia.com/default/topic/1062484/jetson-tx2/for-the-love-of-god-make-spi-easy-to-enable-/post/5381235/#5381235. I too was wondering where to find the tools…the elinux doc (linked above) simply says “in a copy of the kernel sources, change directories to tools/spi/” but they fail to give the absolute path leaving everyone scratching their heads. I was able to find something here on my host OS

~/nvidia/nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/usr/src/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/tools/spi

This directory was created following the SDK Manager setup. I don’t know if this is what @ShaneCCC is referring to by saying “For the tools/spi it’s in the kernel source”. This is just a repeated statement found in the elinux doc (linked above) and offers no support.

Nevertheless, I went to the directory I pointed to above and ran the following command (as the elinux doc says)

CROSS_COMPILE=/usr/bin/aarch64-linux-gnu- make

I get the following output:

make
make: *** No rule to make target ‘spidev_test’, needed by ‘all’. Stop.

The Makefile reads:

CC = $(CROSS_COMPILE)gcc

all: spidev_test spidev_fdx

clean:
	$(RM) spidev_test spidev_fdx

And this is where I’m stuck. The only file in the directory is the Makefile?!?!

Again, I’ve started with the SDK Manager and I’m working with the files installed by it. Starting from here, how do I create the spidev_test binary??

I tried to change the directory to ~/nvidia and run:

sudo find ./ -name “spidev*”

I get the following output:
./nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/usr/src/linux-headers-4.9.140-tegra-linux_x86_64/kernel-4.9/include/uapi/linux/spi/spidev.h
./nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/usr/src/linux-headers-4.9.140-tegra-linux_x86_64/kernel-4.9/include/config/spi/spidev.h
./nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/usr/src/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/include/uapi/linux/spi/spidev.h
./nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/usr/src/linux-headers-4.9.140-tegra-ubuntu18.04_aarch64/kernel-4.9/include/config/spi/spidev.h
./nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/usr/include/linux/spi/spidev.h
./nvidia_sdk/JetPack_4.2.2_Linux_GA_P3310/Linux_for_Tegra/rootfs/lib/modules/4.9.140-tegra/kernel/drivers/spi/spidev.ko

Nothing about “spidev_test” which makes me wonder if I do have to obtain the souces? Maybe the SDK Manager does not natively obtain those sources?

OK…found “spidev_test.c”

The exlinux doc (https://elinux.org/Jetson/TX2_SPI) says:

“L4T source tarball available here: https://developer.nvidia.com/embedded/dlc/l4t-sources-28-1”

Well, obviously this link is not up to date, nor is the instructions generic enough to followed explicitly. That being said, there is a clue in the file name (which I highlighted in bold).

On the host OS

Goto the Jetson Download Center (https://developer.nvidia.com/embedded/downloads) and you can scroll down or use the search filter to find “L4T Sources”. Be sure to download the version that matches the one used in your installed version of JetPack.

I just made a new directory called “kernal_sources” in my home directory and extracted the contents. The “spidev_test.c” can be found in:

~/kernal_sources/public_sources/kernel_src/kernel/kernel-4.9/tools/spi

I’m not sure why, but the SDK Manager does not download all the kernel source files? Therefore, in this case, the elinux doc is correct in telling you that you need to download the source files (albeit the instructions could be more clear and up to date). Nevertheless, performing the following steps will generate the necessary binary:

  1. sudo apt install gcc-aarch64-linux-gnu
  2. cd ~/kernal_sources/public_sources/kernel_src/kernel/kernel-4.9/tools/spi
  3. CROSS_COMPILE=/usr/bin/aarch64-linux-gnu- make

With the Jetson powered up, you can “scp” the binary from the host over to the Jetson:

scp ./spidev_test JETSON_USER_NAME@IP_ADDRESS:/TARGET_DIR/

where you fill in the contents for “JETSON_USER_NAME”, “IP_ADDRESS”, and “TARGET_DIR”. Go over on the Jetson and you should find the binary file you just copied.

On the Jetson

I then followed the test procedures at the end of the elinux doc and executed the following command:

spidev_test -D /dev/spidev3.0

The output reads

spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
RX | 00 00 00 00 00 (all zeros) | …

So, I’ve only got zeros spitting out at me. I think I need to check the pinmux settings.

Will follow up.

Hey! If you want, send me your email by PM and I will send you a document I made to setup SPI and test via Python

I am travelling right now and will be back in my office on Monday 9 sept so I can send you the document then

I was able to edit the pinmux settings and it appears that everything is working. See my final write up here for more details: [url]https://devtalk.nvidia.com/default/topic/1062484/jetson-tx2/for-the-love-of-god-make-spi-easy-to-enable-/post/5381680/#5381680[/url]