I have a problem with configuring SPI on the Jetson Nano development board. Hopefully, anyone here can help me out with solving this problem. I have tried the following:
First I executed the following commands: $ sudo find /opt/nvidia/jetson-io/ -mindepth 1 -maxdepth 1 -type d -exec touch {}/__init__.py \;
@ShaneCCC Thanks for your reply. I don’t think I had Jetpack installed in the first place, so that is one step further. I disabled spi1. rebooted the Jetson, enabled it again, rebooted it, and shorted pin 19 and 21.
This is the output of the spidev_testc
I don’t think it works. I tried this on two different Jetson Nano’s sadly both without result.
Hey @ShaneCCC, I really appreciate your fast response. I tried running the spidev_test and it gave me the same error. I could hook it up to an oscilloscope if that would be more conveniënt?
nvidia@nvidia-desktop:~$ cat /boot/extlinux/extlinux.conf
TIMEOUT 30
DEFAULT JetsonIO
MENU TITLE L4T boot options
LABEL primary
MENU LABEL primary kernel
LINUX /boot/Image
INITRD /boot/initrd
APPEND ${cbootargs} root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0
# When testing a custom kernel, it is recommended that you create a backup of
# the original kernel and add a new entry to this file so that the device can
# fallback to the original kernel. To do this:
#
# 1, Make a backup of the original kernel
# sudo cp /boot/Image /boot/Image.backup
#
# 2, Copy your custom kernel into /boot/Image
#
# 3, Uncomment below menu setting lines for the original kernel
#
# 4, Reboot
# LABEL backup
# MENU LABEL backup kernel
# LINUX /boot/Image.backup
# INITRD /boot/initrd
# APPEND ${cbootargs}
#LABEL JetsonIO
# MENU LABEL Custom Header Config: <HDR40 User Custom [2021-08-10-180616]>
# LINUX /boot/Image
# FDT /boot/kernel_tegra210-p3448-0000-p3449-0000-b00-user-custom.dtb
# INITRD /boot/initrd
# APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0
LABEL JetsonIO
MENU LABEL Custom Header Config: <HDR40 User Custom [2021-09-07-182023]>
LINUX /boot/Image
FDT /boot/kernel_tegra210-p3448-0000-p3449-0000-b00-user-custom.dtb
INITRD /boot/initrd
APPEND ${cbootargs}
nvidia@nvidia-desktop:~$ sudo ./spidev_test -D /dev/spidev0.0 -g16 -zz
using device: /dev/spidev0.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 10000000 Hz (10000 KHz)
no. runs: 1
Using seed:0x619f31ad
loop count = 0
using sequential pattern ....
transfer bytes [16]
0000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
transfer: Return actual transfer length: 16
receive bytes [16]
0000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
/dev/spidev0.0: TEST PASSED
cat /boot/extlinux/extlinux.conf
TIMEOUT 30
DEFAULT JetsonIO
MENU TITLE L4T boot options
LABEL primary
MENU LABEL primary kernel
LINUX /boot/Image
INITRD /boot/initrd
APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0
# When testing a custom kernel, it is recommended that you create a backup of
# the original kernel and add a new entry to this file so that the device can
# fallback to the original kernel. To do this:
#
# 1, Make a backup of the original kernel
# sudo cp /boot/Image /boot/Image.backup
#
# 2, Copy your custom kernel into /boot/Image
#
# 3, Uncomment below menu setting lines for the original kernel
#
# 4, Reboot
# LABEL backup
# MENU LABEL backup kernel
# LINUX /boot/Image.backup
# INITRD /boot/initrd
# APPEND ${cbootargs}
LABEL JetsonIO
MENU LABEL Custom Header Config: <HDR40 User Custom [2021-11-24-085933]>
LINUX /boot/Image
FDT /boot/tegra210-p3448-0000-p3449-0000-b00-user-custom.dtb
INITRD /boot/initrd
APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyS0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0
But when I try the following command:
sudo ./spidev_test -D /dev/spidev0.0 -g16 -zz
It uses SPI 2.0 again. Perhaps because I don’t have a /dev/ folder within my spitest library
Thanks again for your help @ShaneCCC, I appreciate it. I added the file in the directory and made it executable. This is the output
blindsight@blindsight:~/spi_test/spidev-lib$ sudo chmod +x spidev_test
blindsight@blindsight:~/spi_test/spidev-lib$ ./spidev_test
Transaction length not specified
Usage: ./spidev_test [options]
version 21
-D --device device to use (default /dev/spidev0.0)
-s --speed max speed (Hz)
-g --length transaction length in bytes. Multiple lengths can be comma separated.
-z --debug enable debug mode. Specifying more than once to increase the verboisty.
-p --pattern choose pattern type. Available patterns are:
0: sequential bytes
1: even bytes
2: odd bytes
3: reverse sequential bytes
4: random bytes with crc
-F prefix Dump rx/tx buffer as raw to file. With no prefix specified, current pid will be used
-f --file Pattern file. User defined pattern. Not allowed with -p option.
Pattern file must be in space seperated bytes in hex without
"0x" prefix. Sample data: 01 AA 23 5F 3C 12
-d --delay delay (usec). For SPI master this will be the minimum delay
the driver waits before initiating each transfer. For slave
this indicates the max delay that the slave waits before it times out.
-E --expect Expected transaction length in bytes.
To test variable length data transfer feature.
Without this option, spidev_test will assume it as normal transfer
and will validate the actual transferred length with requested transaction length.
Value should be less than or equal to the transaction length.
-b --bpw bits per word
-H --cpha clock phase
-O --cpol clock polarity
-L --lsb least significant bit first
-C --cs-high chip select active high
-n --nruns Number of times to repeat the test. -1 is infinite.
-u --udelay delay b/w initiating each transfer (usec). Multiple delays can be comma separated
-r --receive only receive data
-t --transmit only transmit data
-v --minsize variable length packet start
-V --maxsize variable length packet end
-W --waitb4 wait for a keystroke before the first transfer
-w --stoperr stop on all errors
-P --packet packet mode
Examples:
To transfer 100 messages of 30 bytes each with random bytes,
spidev_test -D/dev/spidev0.0 -s18000000 -n100 -g30 -p4
To transfer 100 messages of sizes 8 and 3986 with delay of 2ms and 8ms respectively,
spidev_test -D/dev/spidev0.0 -s18000000 -n100 -g8,3968 -u2000,8000
To transfer all bytes from user defined pattern file,
spidev_test -D/dev/spidev0.0 -s18000000 -f/path/to/patternfile
To test variable length feature,
spidev_test -D/dev/spidev0.0 -s18000000 -g 30 -E 20
Return codes:
0 successfull transfer. This would mean that what was
transferred was actually received. Note that a success
would make sense only when the spi is run in a loopback
type configuration, i.e., a miso-mosi loopback or a
master-slave loopback
1 Invalid argument
5 I/O error
6 Data mismatch error. The transfer happened but there is
mismatch in tx and rx pattern. Again this makes sense only
for loopback as explained above
22 Invalid argument
blindsight@blindsight:~/spi_test/spidev-lib$ sudo ./spidev_test -D /dev/spidev0.0 -g16 -zz
using device: /dev/spidev0.0
can't open device: No such file or directory
Aborted
blindsight@blindsight:~/spi_test/spidev-lib$
It states ‘command not found’ when I try an example command
blindsight@blindsight:~/spi_test/spidev-lib$ spidev_test -D/dev/spidev0.0 -s18000000 -n100 -g30 -p4
bash: spidev_test: command not found
@ShaneCCC that was the solution. The test passed now. Do you have the source code for me for that spidev_test file? The .txt is already compiled. This way I can implement this solution now I know that SPI0 could work
blindsight@blindsight:~/Downloads$ sudo ./spidev_test -D /dev/spidev0.0 -g16 -zzusing device: /dev/spidev0.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 10000000 Hz (10000 KHz)
no. runs: 1
Using seed:0x61a0d887
loop count = 0
using sequential pattern ....
transfer bytes [16]
0000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
transfer: Return actual transfer length: 16
receive bytes [16]
0000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
/dev/spidev0.0: TEST PASSED