# Why SPI Displays Don’t “Just Work” on Jetson Orin Nano

## Метаданные

- **Канал:** JetsonHacks
- **YouTube:** https://www.youtube.com/watch?v=BOvVl0WT8fE

## Содержание

### [0:00](https://www.youtube.com/watch?v=BOvVl0WT8fE) Segment 1 (00:00 - 05:00)

In this video, we're bringing up a 2-in spy display on a Jetson Orin Nano using a device tree overlay. Then, we'll build our own custom overlay to enable spy UART and GPIO on the expansion header. Hello, it's Jim from jetsonhacks. com. First, we'll install our spy overlay on the Jetson Hacks account on GitHub. There is a repository named Jetson Orin Spy overlay guide. Let's clone that repository and switch to that repositories directory. We'll scroll down a bit in the readme to the quick start. Then we'll switch directories to get to the overlay for the Jetson default wiring. Finally, we'll run an installation script which copies a compiled device tree overlay to the /boot directory and modifies the XT Linux. config file to use the overlay. We reboot the Jetson for the changes to take effect. When the Jetson reboots and gets to the initial splash screen, you can see that our new overlay has been installed, the Jetson will boot using this overlay, but you have the option of selecting the default configuration by hitting zero during this part of the boot process. In the tools directory, there is a pin inspector which allows us to examine how an expansion header pin is currently configured. Let's take a look at pin 29. You can see that pin 29 is currently configured as GPIO. You may notice in the PIN inspector that a PIN shows up as hoged on Jetson. That just means the colonel has already claimed the PIN early in boot to enforce a known state. It doesn't mean the PIN is unusable. There's more useful information here. We'll cover that later in the video. Now, we're ready to install our driver library. Let's switch over to Jetson-OrIN-ST7789. Let's make sure that our spy device now exists. There it is. Next, we'll add ourselves to the GPIO and dial out groups so that we don't have to use sudo to work with the pins. Now, I'm going to install UV for the Python virtual environment manager. We clone the repository and switch to that repositories directory. We use uv sync to build the library and install dependencies. Then we run a quick test to make sure everything installed correctly. Power down the Jetson and we'll connect the ST7789 display. Here's the wiring connections on the expansion header. Pin one is on the edge of the board, closest to the USB ports. Odd numbered pins are towards the edge of the board. Even center of the board. Power up the Jetson and we're ready to give it a spin. We're in the examples folder. Let's run the unit tests. The first couple of tests display solid colors on the display. Then we start displaying some patterns. Geometric shapes are next, followed up by some text. There's also a simple system monitor demonstration showing some supplemental user interface ideas. This is simulated data. You can monitor the Jetson directly by installing the PSU till library. You can also rotate the display graphics to fit your installation orientation. Look through the examples and code to get a feel for the capabilities. Now, let's go over an example. We will enable both spy and UART ports along with a couple of GP IO pins. First, we open Jetson IO. Next, we configure the Jetson 40 pin and configure header pins manually. Some pins on the expansion header connect to special function hardware blocks. This is the list of those special functions and their associated pins. We'll select spy one, which sets up these five pins.

### [5:00](https://www.youtube.com/watch?v=BOvVl0WT8fE&t=300s) Segment 2 (05:00 - 10:00)

The transmit and receive pins for the UART are enabled by default. While we're here, let's also enable the hardware handshake. Now, we select back and export as device tree overlay. That saves the new compiled device tree overlay to the /boot directory. You'll need to be a little careful here. This will overwrite any file with the same name. Okay, we've created a new device tree overlay with the special functions enabled. Now, we need to add any GPIO pins we might need. I'll create a new directory and copy our overlay from /boot. Now let's use the device tree compiler to decompile the binary overlay to source code. The command takes us input the DTB binary and outputs it to a DTS source file. I'll open the device tree overlay source file in VS Code. We now have the overlay source. Before we can modify and compile it, however, a few of the references need to be converted into proper labels. In the Jetson Orin SPI overlay guide we cloned earlier, there is a tool named DTS Convert. I'll copy that script into the current working directory. Then we convert the source file to make it easier to work with. I'll rename the original and change the name of the converted file to be spyart. Let's throw it over into VS Code. We'll switch over into our tools directory so we can use the pin inspector. Let's use pin 29 as one of our GPIO pins. The pin inspector gives us a bunch of information about the current pin configuration. More importantly, here's a source code fragment we can use to configure the pin to be GPIO. Let's copy the fragment and place it into our overlay file. We'll also use pin 31 as GPIO. Let's grab that source code fragment and place it into our source file. Make sure to save the file after changing it. Now we switch back over to our working directory. While we're at it, let's change the overlay name that's at the top of the source file. Save the file and we're ready to compile it into an overlay. Oops, fat fingered it. Try it again. This time for sure. Next, we place the compiled overlay into the /boot directory. Now we are ready to install the overlay into the system. We'll use Jetson IO to help configure Jetson 40 pin header. Configure for compatible hardware. We'll select our overlay name. Our little map here is updated to reflect the changes we made to the spy and UART. Looking good. Save pin changes. Then we save and reboot to reconfigure the pins. As you can see, we now have our new overlay as a boot option. An important thing to note here, it's entirely possible to create an overlay that causes the machine not to boot. I'm sure you would never do that, but if a friendmy does, selecting zero primary kernel at this point will cause the default machine configuration to load. We'll run Jetson IO to make sure everything took. Unfortunately, it doesn't show GPIO. Everything looks good. Let's test the GPIO. Let's get out the old multimeter. Before wiring anything to the Jetson, the board should be powered off. On the expansion header, pin one is on the edge of the board, closest to the USB ports. Odd numbered pins are towards the edge of the board. Even center of the board. We'll test pin 31 here and use pin 6 for ground. We also have pin 29 configured on the Jetson. Let's switch back to the tools directory. I want to run the blink test on pin 31. Let's see how to do that. We'll use 31 and the blink flag. Oh, that's a little bit of a kurfuffle. It looks like I need to install the GPOD library.

### [10:00](https://www.youtube.com/watch?v=BOvVl0WT8fE&t=600s) Segment 3 (10:00 - 12:00)

Finally, we are ready to run our blink test. The blink test turns the pin high, which is 3. 3 volts, and then switches it to low, which is 0 volt. Here's a subtle one that trips people up on the Jetson Nano. You set a pin high, grab a multimeter, and instead of 3. 3 volts, you see something like 1. 7 volts. The pin isn't broken. It's trying to drive 3. 3 volts, but the drive current isn't strong enough to supply the load of the measurement itself. So, the voltage never quite gets there. Whether you can fix that depends on which pin you chose. On the 40 pin header, only 6GPIO capable pins use double drive pads. On those pins, you can increase the output drive strength in a device tree overlay. The other six use standard pads where the drive strength is fixed. This applies to more than just GPIO. Some SFIO pins like the SPI clock also sit on double drive pads. That's why increasing drive strength can fix reliability issues with certain SPI devices. If the pin is on a double drive pad, you can increase its output current by setting pull-up strength and pull down strength in a device tree overlay. If it's a standard pad, you can't. Compiled device tree and device tree overlays are stored in the /boot directory. You can use multiple overlays, but they must be for different hardware sections. For example, you may define the expansion header and the CSI camera configuration using two different overlays. The overlays are not additive. In other words, you can't have two overlays which describe the expansion header. As a side note, the device tree files are named according to Nvidia part number. Let's take a look at an important file, the configuration for the bootloadader. The Linux system configuration file is in XT Linux. You'll need sudo to edit it. This is the file that the system relies on to configure the Jetson, so you'll want to be careful here. The entry fdt is the name of the flattened device tree file to use and overlays is a list of the overlay names separated by commas. If you followed the steps in the video, Jetson IO will take care of this for you. If you are more experienced, you can edit this directly. It's very low level and it's possible to create a file which the Jetson will not boot from. Make sure to have backups. The device tree describes the entire Jetson from the CPU and GPU down to the expansion header pins. As such, the full device tree is very large. It is certainly difficult to understand on its own. However, by using device tree overlays, we can add bits and pieces here and there which greatly simplify development. The expansion header is small enough to get a good grasp on. If you want further explanations about the device tree, let me know in the comments below.

---
*Источник: https://ekstraktznaniy.ru/video/39290*