SPI communication on Jetson Nano

how can I enable SPI communication on Jetson Nano board, As I have installed “spidev” library but its not working.

Have a reference to this link. Please update the dtb file by flash instead of modify the extlinux.conf
https://elinux.org/Jetson/TX1_SPI

I am new to this board as well as linex system. i followed the reference provided by you but got nothing.
please tell me how can i enable SPI communication on jetson nano board. as I am continuously receiving error.

Board Info: {‘P1_REVISION’: 1, ‘RAM’: ‘4096M’, ‘REVISION’: ‘Unknown’, ‘TYPE’: ‘Jetson Nano’, ‘PROCESSOR’: ‘ARM A57’, ‘MANUFACTURER’: ‘NVIDIA’}
Board pin mode: BOARD
Traceback (most recent call last):
File “JETSON_ADS.py”, line 62, in
spi.open(1, 1) # open spi port 0, device (CS)1
IOError: [Errno 2] No such file or directory


(program exited with code: 1)
Press return to continue

I can’t answer the specifics of your question, but you will need to change the device tree. The device tree is more or less a series of key/value options which drivers can see (and ignore or use). Drivers related to SPI use some of this content.

The application which compiles a device tree source into binary (or decompiles) is “dtc”. To install this run command:

sudo apt-get install device-tree-compiler

To get the current device tree which reflects the exact current running system in source form:

dtc -I fs -O dts -o extracted.dts /proc/device-tree

This file can be edited with any text editor. This is in a tree-like format where there is a key word, and content…either more nodes, or actual data. When you see something similar to this (from the URL above):

+        gpio: gpio@6000d000 {
+                gpio_default: default {
+                       gpio-to-sfio = <16 17 18 19 20>;
+               };

…the “+” is just “add”, where as a “-” would be removed…lines without a “+” or “-” of a patch are unchanged lines, and “@” lines give hints on the line number.

The “gpio@6000d000” is a GPIO controller at base address 0x6000d000. Any content in this would be used by that specific GPIO controller. Some pins may have multiple possible functions, and thus GPIO could be involved.

Once you have edited a device tree source file you can compile it (assumes you modified “extracted.dts”):

dtc -I dts -O dtb -o edited_and_compiled.dtb extracted.dts

Where the above URL fails is for newer releases (your release is visible via “head -n 1 /etc/nv_tegra_release”). In older releases this was simply a file copy into “/boot”. However, newer releases have required this tree at earlier boot stages, and those boot stages cannot read the ext4 file system. Thus the dtb is now in its own partition. To complicate this the tree needs to be signed. Thus if you look at the documents for R32.1 (the only thing the Nano works with so far since it is new) you will get information on flashing a device tree.

Normally device tree comes in different pieces with the kernel code. For that reason you will often see kernel build steps, but device tree is actually independent of kernel. It happens that certain kernel drivers are paired with certain device trees, and thus depending on how you’ve configured the kernel those different pieces get assembled as well and integrated into a single dtb based on options. However you get a dtb file does not matter so long as the configuration of the dtb works with the particular kernel release with its given configuration. The URL above names SPI edits, and this should apply to the R32.1 kernel as well. Should you see documents talking about “.dtsi” files and kernel build don’t let it complicate things…the above manual edit is similar.

Assuming you are using SDK Manager in Linux:

If you look in your flash directory after SDK Manager has flashed you will find the core of flash is the subdirectory “Linux_for_Tegra/”. Within this is a “bootloader/” subdirectory. From here you can see many possible device trees, each of which is used with different types of Jetsons and carrier boards:

cd /where/ever/it/is/Linux_for_Tegra/bootloader/
find . -name '*.dtb'

If you have a log of flashing, then you would notice one of these “.dtb” files is used. You can reverse compile that dtb and view or edit this (I’m just picking an example file, this will be incorrect for your case, but adjust…assumes you have used “cd” to go to the correct directory first):

dtc -I dtb -O dts -o source_dts.dts tegra194-a02-bpmp-p2888-a04-maxn.dtb
# Now edit source_dts.dts, recompile it, save a backup of the original dtb, and replace it
# with your altered dtb...flash.
dtc -I dts -O dtb -o modified.dtb source_dts.dts
cp tegra194-a02-bpmp-p2888-a04-maxn.dtb original_tegra194-a02-bpmp-p2888-a04-maxn.dtb
cp modified.dtb tegra194-a02-bpmp-p2888-a04-maxn.dtb
# Flash or install based on this. References to simply copying to a "/boot" location
# are out of date and used with older releases.

i have edited and compiled the dtb file. now i have @edited_and_compiled.dtb extracted.dts file.
now how can i flash this file to my jetson nano board.

Have a reference to below topic to flash your device.
You may need download the source code to modify and compile the dtb instead of use dtc for Nano.

https://devtalk.nvidia.com/default/topic/1051483

could not flash the dtb file.

  1. ./flash.sh command not found as i tried on terminal window.

  2. how can i flash the modified dtb file?

“flash.sh” is part of the driver package. When you run SDK Manager for flash it downloads this for you. I forget which subdirectory is for nano, but one of the “~/nvidia/nvidia_sdk/JetPack_4.2_Linux_P####/Linux_for_Tegra/” directories will contain the correct flash.sh. Just “cd” to that location and it should work.

Tip: “.” implies the directory you are currently in. “./flash.sh” implies the “flash.sh” of the directory you are currently in.

Thanks for you kind reply, as i am working of Jetson Nano booted from SD card. Now my question is that to flash the modified #dtb file into the board is @sdk manager is necessary to be installed on jetson board or on host machine?

The SDK Manager is running on host machine.

i have succeeded to flash the new dtb file and make spidev module available on #lsmod list. now can you please tell me how can I run loopback test on jetson nano board.

hi manjeet.
how do you did to flash dtb file?

Hi @wahsiu,

Running the following will flash the dtb files in Linux_for_Tegra/kernel/dtb/.

sudo ./flash.sh --no-systemimg -k DTB jetson-nano-qspi-sd mmcblk0p1

I published the .dts file and the flash script here: https://github.com/rt-net/JetsonNano_DT_SPI
I hope this helps.

https://devtalk.nvidia.com/default/topic/1050427/jetson-nano/enabling-spidev-on-the-jetson-nano-is-hanging-when-flashing/post/5339816/#5339816

thanks tiryoh,i had tried as following ,but dont work,i dont know is there any process wrong.

hispacen1n@ubuntu:~/Downloads$ cp modified-gpio.dtb ~/Downloads/nvidia/Linux_for_Tegra/kernel/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb
hispacen1n@ubuntu:~/Downloads$ ls
extlinux.conf  extracted2.dts  extracted.dts  modified-gpio.dtb  nvidia
hispacen1n@ubuntu:~/Downloads$ lsusb 
Bus 001 Device 013: ID 0955:7f21 NVidia Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
hispacen1n@ubuntu:~/Downloads$ cd nvidia/Linux_for_Tegra/
hispacen1n@ubuntu:~/Downloads/nvidia/Linux_for_Tegra$ ls
apply_binaries.sh                    flash.sh                  kernel           p2371-2180.conf              p3448-0000.conf.common  TX1_boot-firmware-redundancy.txt
bootloader                           jetson-nano-qspi.conf     lib              p2371-2180-devkit-24x7.conf  p3448-0000-sd.conf
create-jetson-nano-sd-card-image.sh  jetson-nano-qspi-sd.conf  nv_tegra         p2371-2180-devkit.conf       rootfs
elf-get-entry.py                     jetson-tx1.conf           p2371-0000.conf  p3448-0000.conf              source_sync.sh
hispacen1n@ubuntu:~/Downloads/nvidia/Linux_for_Tegra$ sudo ./flash.sh -r -k DTB jetson-nano-qspi-sd mmcblk0p1
[sudo] password for hispacen1n: 
###############################################################################
# L4T BSP Information:
# Unknown Release
###############################################################################
# Target Board Information:
# Name: jetson-nano-qspi-sd, Board Family: t210ref, SoC: Tegra 210, 
# OpMode: production, Boot Authentication: , 
###############################################################################
./tegraflash.py --chip 0x21 --applet "/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/nvtboot_recovery.bin" --skipuid --cmd "dump eeprom boardinfo cvm.bin" 
Welcome to Tegra Flash
version 1.0.0
Type ? or help for help and q or quit to exit
Use ! to execute system commands
 
[   0.0498 ] Generating RCM messages
[   0.1329 ] tegrarcm --listrcm rcm_list.xml --chip 0x21 0 --download rcm /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/nvtboot_recovery.bin 0 0
[   0.1367 ] RCM 0 is saved as rcm_0.rcm
[   0.3083 ] RCM 1 is saved as rcm_1.rcm
[   0.3084 ] List of rcm files are saved in rcm_list.xml
[   0.3084 ] 
[   0.3085 ] Signing RCM messages
[   0.3127 ] tegrasign --key None --list rcm_list.xml --pubkeyhash pub_key.key
[   0.3703 ] Assuming zero filled SBK key
[   0.4683 ] 
[   0.4684 ] Copying signature to RCM mesages
[   0.4697 ] tegrarcm --chip 0x21 0 --updatesig rcm_list_signed.xml
[   0.5088 ] 
[   0.5089 ] Boot Rom communication
[   0.5103 ] tegrarcm --chip 0x21 0 --rcm rcm_list_signed.xml --skipuid
[   0.5127 ] RCM version 0X210001
[   0.9497 ] Boot Rom communication completed
[   1.9980 ] 
[   1.9982 ] dump EEPROM info
[   1.9994 ] tegrarcm --oem platformdetails eeprom /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/cvm.bin
[   2.0050 ] Applet version 00.01.0000
[   2.1416 ] Saved platform info in /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/cvm.bin
[   2.2812 ] 
Board ID(3448) version(200) 
copying bctfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/BCT/P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.cfg)... done.
copying bootloader(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/cboot.bin)... done.
	populating kernel to rootfs... done.
	populating initrd to rootfs... done.
	populating extlinux.conf.emmc to rootfs... done.
	populating /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/kernel/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb to rootfs... done.
done.
Making Boot image... done.
head: cannot open '/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/rootfs/etc/nv_tegra_release' for reading: No such file or directory
Existing sosfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/nvtboot_recovery.bin) reused.
copying tegraboot(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/nvtboot.bin)... done.
copying cpu_bootloader(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/cboot.bin)... done.
copying bpffile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/sc7entry-firmware.bin)... done.
Existing badpagefile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/badpage.bin) reused.
copying wb0boot(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/warmboot.bin)... done.
Existing tosfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/tos-mon-only.img) reused.
Existing eksfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/eks.img) reused.
copying dtbfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/kernel/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb)... done.
Reusing existing system.img... 
done.
Existing tbcfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/nvtboot_cpu.bin) reused.
copying tbcdtbfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/kernel/dtb/tegra210-p3448-0000-p3449-0000-a02.dtb)... done.
copying cfgfile(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/cfg/flash_l4t_t210_spi_sd_p3448.xml) to flash.xml... done.
copying flasher(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/t210ref/cboot.bin)... done.
Existing flashapp(/home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/tegraflash.py) reused.
*** Updating [DTB] with tegra210-p3448-0000-p3449-0000-a02.dtb ***
./tegraflash.py --bl cboot.bin --bldtb tegra210-p3448-0000-p3449-0000-a02.dtb  --chip 0x21 --applet nvtboot_recovery.bin --bct  P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.cfg  --cfg  flash.xml   --cmd "sign; write DTB ./signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt; reboot"  
Welcome to Tegra Flash
version 1.0.0
Type ? or help for help and q or quit to exit
Use ! to execute system commands
 
[   0.1075 ] Generating RCM messages
[   0.1086 ] tegrarcm --listrcm rcm_list.xml --chip 0x21 0 --download rcm nvtboot_recovery.bin 0 0
[   0.1096 ] RCM 0 is saved as rcm_0.rcm
[   0.1106 ] RCM 1 is saved as rcm_1.rcm
[   0.1115 ] List of rcm files are saved in rcm_list.xml
[   0.1224 ] 
[   0.1225 ] Signing RCM messages
[   0.1448 ] tegrasign --key None --list rcm_list.xml --pubkeyhash pub_key.key
[   0.1460 ] Assuming zero filled SBK key
[   0.1687 ] 
[   0.1695 ] Copying signature to RCM mesages
[   0.1708 ] tegrarcm --chip 0x21 0 --updatesig rcm_list_signed.xml
[   0.1923 ] 
[   0.1924 ] Parsing partition layout
[   0.2202 ] tegraparser --pt flash.xml.tmp
[   0.3066 ] 
[   0.3068 ] Creating list of images to be signed
[   0.3510 ] tegrahost --chip 0x21 0 --partitionlayout flash.xml.bin --list images_list.xml
[   0.5400 ] 
[   0.5402 ] Generating signatures
[   0.5411 ] tegrasign --key None --list images_list.xml --pubkeyhash pub_key.key
[   0.5420 ] Assuming zero filled SBK key
[   0.6840 ] 
[   0.6841 ] Generating br-bct
[   0.6852 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.cfg --chip 0x21 0
[   0.7038 ] Copying Sdram info from 0 to 1 set
[   0.8922 ] Copying Sdram info from 1 to 2 set
[   0.8938 ] Copying Sdram info from 2 to 3 set
[   0.9041 ] 
[   0.9045 ] Updating boot device parameters
[   0.9071 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --updatedevparam flash.xml.bin
[   0.9110 ] Warning: No sdram params
[   0.9520 ] 
[   0.9522 ] Updating bl info
[   0.9535 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --updateblinfo flash.xml.bin --updatesig images_list_signed.xml
[   0.9949 ] 
[   0.9951 ] Updating secondary storage information into bct
[   0.9960 ] tegraparser --pt flash.xml.bin --chip 0x21 0 --updatecustinfo P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct
[   1.0129 ] 
[   1.0129 ] Get Signed section of bct
[   1.0139 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --listbct bct_list.xml
[   1.0283 ] 
[   1.0284 ] Signing BCT
[   1.0329 ] tegrasign --key None --list bct_list.xml --pubkeyhash pub_key.key
[   1.0338 ] Assuming zero filled SBK key
[   1.0515 ] 
[   1.0516 ] Updating BCT with signature
[   1.0527 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --updatesig bct_list_signed.xml
[   1.0692 ] 
[   1.0692 ] Copying signatures
[   1.0703 ] tegrahost --chip 0x21 0 --partitionlayout flash.xml.bin --updatesig images_list_signed.xml
[   1.0962 ] 
[   1.0966 ] Copying signed file in /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/signed
[   1.1339 ] Generating RCM messages
[   1.1351 ] tegrarcm --listrcm rcm_list.xml --chip 0x21 0 --download rcm nvtboot_recovery.bin 0 0
[   1.1404 ] RCM 0 is saved as rcm_0.rcm
[   1.1433 ] RCM 1 is saved as rcm_1.rcm
[   1.1464 ] List of rcm files are saved in rcm_list.xml
[   1.1610 ] 
[   1.1611 ] Signing RCM messages
[   1.1625 ] tegrasign --key None --list rcm_list.xml --pubkeyhash pub_key.key
[   1.1652 ] Assuming zero filled SBK key
[   1.1887 ] 
[   1.1887 ] Copying signature to RCM mesages
[   1.1898 ] tegrarcm --chip 0x21 0 --updatesig rcm_list_signed.xml
[   1.2065 ] 
[   1.2067 ] Boot Rom communication
[   1.2077 ] tegrarcm --chip 0x21 0 --rcm rcm_list_signed.xml
[   1.2090 ] BootRom is not running
[   1.7779 ] 
[   1.7780 ] Parsing partition layout
[   1.8029 ] tegraparser --pt flash.xml.tmp
[   1.8422 ] 
[   1.8425 ] Creating list of images to be signed
[   1.8485 ] tegrahost --chip 0x21 0 --partitionlayout flash.xml.bin --list images_list.xml
[   1.9201 ] 
[   1.9203 ] Generating signatures
[   1.9374 ] tegrasign --key None --list images_list.xml --pubkeyhash pub_key.key
[   1.9419 ] Assuming zero filled SBK key
[   2.0561 ] 
[   2.0562 ] Send BCT from Host
[   2.0562 ] Generating br-bct
[   2.0573 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.cfg --chip 0x21 0
[   2.0583 ] Copying Sdram info from 0 to 1 set
[   2.0601 ] Copying Sdram info from 1 to 2 set
[   2.0646 ] Copying Sdram info from 2 to 3 set
[   2.0734 ] 
[   2.0735 ] Updating boot device parameters
[   2.0745 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --updatedevparam flash.xml.bin
[   2.0755 ] Warning: No sdram params
[   2.0881 ] 
[   2.0882 ] Updating bl info
[   2.0893 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --updateblinfo flash.xml.bin --updatesig images_list_signed.xml
[   2.1040 ] 
[   2.1058 ] Updating secondary storage information into bct
[   2.1075 ] tegraparser --pt flash.xml.bin --chip 0x21 0 --updatecustinfo P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct
[   2.1217 ] 
[   2.1224 ] Get Signed section of bct
[   2.1236 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --listbct bct_list.xml
[   2.1370 ] 
[   2.1387 ] Signing BCT
[   2.1413 ] tegrasign --key None --list bct_list.xml --pubkeyhash pub_key.key
[   2.1446 ] Assuming zero filled SBK key
[   2.1622 ] 
[   2.1623 ] Updating BCT with signature
[   2.1634 ] tegrabct --bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct --chip 0x21 0 --updatesig bct_list_signed.xml
[   2.1787 ] 
[   2.1788 ] Sending BCTs
[   2.1806 ] tegrarcm --download bct P3448_A00_4GB_Micron_4GB_lpddr4_204Mhz_P987.bct
[   2.1830 ] Applet version 00.01.0000
[   2.3366 ] Sending bct
[   2.3367 ] [................................................] 100%
[   2.4587 ] 
[   2.4588 ] Sending bootloader and pre-requisite binaries
[   2.4599 ] tegrarcm --download ebt cboot.bin 0 0 --download rp1 tegra210-p3448-0000-p3449-0000-a02.dtb 0
[   2.4610 ] Applet version 00.01.0000
[   2.5980 ] Sending ebt
[   2.5984 ] [................................................] 100%
[   2.7741 ] Sending rp1
[   2.7942 ] [................................................] 100%
[   2.9980 ] 
[   3.0042 ] tegrarcm --boot recovery
[   3.0094 ] Applet version 00.01.0000
[   3.1967 ] 
[   3.1968 ] Writing partition
[   3.1978 ] tegradevflash --write DTB /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt
[   3.2213 ] Cboot version 00.01.0000
[   4.0749 ] Writing partition DTB with /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt
[   4.0881 ] 00000004: Filesize is bigger than partition size
[   4.1374 ] 
Error: Return value 4
Command tegradevflash --write DTB /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt
Failed to flash/read t210ref.

hi tiryoh,i had tried as your following,but it failed.

hispacen1n@ubuntu:~/Downloads/nvidia/Linux_for_Tegra$ sudo ./flash.sh --no-systeming -k DTB jetson-nano-qspi-sd mmcblk0p1
...
[   3.2734 ] 00000004: Filesize is bigger than partition size
[   3.3402 ] 
Error: Return value 4
Command tegradevflash --write DTB /home/hispacen1n/Downloads/nvidia/Linux_for_Tegra/bootloader/signed/tegra210-p3448-0000-p3449-0000-a02.dtb.encrypt
Failed to flash/read t210ref.

Hi wahsiu,
Does the SD card have enough size and free space?

yes,my SD card is 64GB

@wahsiu,

I saw the log file you uploaded here:
https://devtalk.nvidia.com/default/topic/1051483/jetson-nano/spi-communication-on-jetson-nano/post/5343544/#5343544

# L4T BSP Information:
# Unknown Release

It says that L4T BSP Information is Unknown(on line 9 to 10). Maybe the L4T version does not match.
How about re-downloading and re-flashing L4T(R32.1)?

i had flash dtb file successfully,but it got stuck when i reboot.

i had dowmloaded L4T 32.1(Jetson Nano Drivers->BSP) on my host pc(ubuntu18.04) again.but there is still the same issue

###############################################################################
# L4T BSP Information:
# Unknown Release
###############################################################################