# Jetson Nano access to SPI device

**URL:** <https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471>\
**Category:** balenaOS\
**Tags:** nvidia, jetson, jetpack\
**Created:** [January 26, 2020, 2:15pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471 "2020-01-26T14:15:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 26, 2020, 2:15pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/1 "2020-01-26T14:15:48Z")

</div>

Hi everyone,

I would like to use the SPI device `/dev/spidev0.0` inside my container. But sadly Nvidia does not support these in the base image by default. Therefore users needs to modify their device tree in order to access the `/dev/spidev0.0` device.  
Any clues on how i could modify the the BalenaOS for the Jetson Nano accordingly?

[Here is a great GitHub](https://github.com/rt-net/JetsonNano_DT_SPI) project that describes how the device tree can be modified.  
Furthermore [eLinux](https://elinux.org/Jetson/TX1_SPI) describes it in more detail for the similar TX1 station

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 26, 2020, 5:34pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/2 "2020-01-26T17:34:41Z")

</div>

It seems like the tx-2 has already a patch in place. So the changes probably need to be made similarly. Sadly i have only a rough understanding of the yocto project, therefore i highly appreciate some help 🙂

> <https://github.com/balena-os/balena-jetson/blob/master/layers/meta-balena-jetson/recipes-kernel/linux/linux-tegra/0001-Expose-spidev-to-the-userspace.patch>

---

<div class="post-metadata">

**Author:** ![ffissore](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ffissore/32/2842_2.png) [@ffissore](https://forums.balena.io/u/ffissore)\
**Post date:** [January 27, 2020, 1:19pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/3 "2020-01-27T13:19:23Z")

</div>

Hi Frederic,

I’m sorry but it’s unclear which similar changes need to be made. spi0 is already available on the jetson-nano. Is this the board you’re using? what device is still missing when using balenaOS?

Regards

federico

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 1:56pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/5 "2020-01-27T13:56:55Z")

</div>

Hmm, i will flash a fresh image provided by [balena.io](http://balena.io) maybe i was just running an old prebuild OS and the yocto toolchain provides something different.

Furthermore, I build a fresh balena OS image yesterday with the yocto tool chain and i could not find any /dev/spi\* device when i used ssh to access the host system on the Jetson Nano.

Its running

```auto
SUPERVISOR VERSION: 10.3.7
OS VERSION: balenaOS 2.45.1+rev3

```

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 2:17pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/6 "2020-01-27T14:17:35Z")

</div>

> [@ffissore](#):
>
> I’m sorry but it’s unclear which similar changes need to be made. spi0 is already available on the jetson-nano. Is this the board you’re using? what device is still missing when using balenaOS?

Just to do a sanity check, how did you access the spi device?

---

<div class="post-metadata">

**Author:** ![ffissore](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ffissore/32/2842_2.png) [@ffissore](https://forums.balena.io/u/ffissore)\
**Post date:** [January 27, 2020, 2:44pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/7 "2020-01-27T14:44:07Z")

</div>

I didn’t, I assumed there is, given the patch in the repo. I’ll double check with the OS team. Any luck with the image we provide?

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:13pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/9 "2020-01-27T16:13:46Z")

</div>

Sadly it did not work.

---

<div class="post-metadata">

**Author:** ![ffissore](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ffissore/32/2842_2.png) [@ffissore](https://forums.balena.io/u/ffissore)\
**Post date:** [January 27, 2020, 4:15pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/10 "2020-01-27T16:15:45Z")

</div>

When listing devices from the host OS (not a container) do you see any spi devices listed?

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:16pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/11 "2020-01-27T16:16:28Z")

</div>

No, i do not see any devices on the host OS. I am not running any container and just using ssh to access the host OS.

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:17pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/12 "2020-01-27T16:17:31Z")

</div>

In order to get it working with the stock Nvidia image i needed to do a couple of changes in the device tree. Nvidia uses the default SPI GPIOs (similar to the Raspberry PI SPI GPIOs) for a different purpose and therefore changes to the device tree are needed.

I used the changed device tree in order to create a patch in the yocto build pipeline. Similar to what you did for the JN30B board (Jetson Nano distribution), but the build fails. As a side note it fails for a fresh repo clone for the JN30B, too. Therefore i am confident, that the approach might work, but my setup might be broken 😕

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:18pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/13 "2020-01-27T16:18:32Z")

</div>

> [@ffissore](#):
>
> When listing devices from the host OS (not a container) do you see any spi devices listed?

If it works for you, what version of the hostOS are you running? Maybe i am just using the wrong build 😕

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:21pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/14 "2020-01-27T16:21:08Z")

</div>

> [@Langhalsdino](#):
>
> In order to get it working with the stock Nvidia image i needed to do a couple of changes in the device tree. Nvidia uses the default SPI GPIOs (similar to the Raspberry PI SPI GPIOs) for a different purpose and therefore changes to the device tree are needed.
> 
> I used the changed device tree in order to create a patch in the yocto build pipeline. Similar to what you did for the JN30B board (Jetson Nano distribution), but the build fails. As a side note it fails for a fresh repo clone for the JN30B, too. Therefore i am confident, that the approach might work, but my setup might be broken 😕

My logfile output lists no clear reason why it fails. Can you confirm that the JN30B build works on your end?

```bash
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: resin-image-1.0-r0 do_image_resinos_img: Function failed: do_image_resinos_img (log file is located at /yocto/balena-jetson/build/tmp/work/jn30b_nano-poky-linux/resin-image/1.0-r0/temp/log.do_image_resinos_img.28812)
ERROR: Logfile of failure stored in: /yocto/balena-jetson/build/tmp/work/jn30b_nano-poky-linux/resin-image/1.0-r0/temp/log.do_image_resinos_img.28812

```

---

<div class="post-metadata">

**Author:** ![ffissore](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/ffissore/32/2842_2.png) [@ffissore](https://forums.balena.io/u/ffissore)\
**Post date:** [January 27, 2020, 4:38pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/15 "2020-01-27T16:38:00Z")

</div>

Hi

Can you tell me again the exact model of the board you’re using? I’m going to check this with the device team

Cheers

federico

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:41pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/16 "2020-01-27T16:41:09Z")

</div>

We are using the Jetson Nano 180-13449-DAAF-A02 dev board. The one that is available in Europe and can be purchased through nvidia resellers such as silicon highways.

Furthermore the Nvidia Jetson Nano Model P3448

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:45pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/17 "2020-01-27T16:45:57Z")

</div>

@ffissore do you know more about my issue on building the jn30b-nano board image from source?

I can create a new forum entry, since it is kind of unrelated to this issue.

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 4:52pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/18 "2020-01-27T16:52:35Z")

</div>

> [@Langhalsdino](#):
>
> I can create a new forum entry, since it is kind of unrelated to this issue.

I created a new forum entry for this challenge.

> [@Building the JN30B-nano image from source](https://forums.balena.io/t/building-the-jn30b-nano-image-from-source/59934):
>
> Hi, I tried to build the jn30b-nano image from source. Using the steps described by the [balena-jeston](https://github.com/balena-os/balena-jetson) repository. It fails during the do\_image\_resinos\_img step. Sadly i do not get any real information on why it fails through the logs. Does anyone have Ideas on what i should look into? NOTE: Executing SetScene Tasks NOTE: Executing RunQueue Tasks ERROR: resin-image-1.0-r0 do\_image\_resinos\_img: Function failed: do\_image\_resinos\_img (log file is located at /home/?/yocto/balena-jetson/build/tmp/w…

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 8:37pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/20 "2020-01-27T20:37:35Z")

</div>

I managed to build my own image with `spidev0.0` support and will do a pull request soon 🙂

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 27, 2020, 9:20pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/22 "2020-01-27T21:20:48Z")

</div>

Here is the [pull request](https://github.com/balena-os/balena-jetson/pull/38)

---

<div class="post-metadata">

**Author:** ![dtischler](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dtischler/32/2483_2.png) [@dtischler](https://forums.balena.io/u/dtischler)\
**Post date:** [January 27, 2020, 10:16pm UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/23 "2020-01-27T22:16:29Z")

</div>

Hi Frederic, I was just looking through the Forums, and found this great news! I am glad to see you got this working, and thanks for submitting a PR, we’ll review it and let you know the results. 🙂

---

<div class="post-metadata">

**Author:** ![Langhalsdino](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/langhalsdino/32/3039_2.png) [@Langhalsdino](https://forums.balena.io/u/Langhalsdino)\
**Post date:** [January 30, 2020, 10:26am UTC](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471/26 "2020-01-30T10:26:21Z")

</div>

@dtischler There is still a bug in the linux kernels driver, that needs to be patched. Sadly i have no clue how to apply the patch correctly.

```auto
diff a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
--- drivers/gpio/gpio-tegra.c
+++ drivers/gpio/gpio-tegra_new.c
@@ -223,10 +223,18 @@
        return pinctrl_request_gpio(chip->base + offset);
 }

+static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio)
+{
+ tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 0);
+}
+
 static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)
 {
+ struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
+
        pinctrl_free_gpio(chip->base + offset);
        tegra_gpio_restore_gpio_state(offset);
+ tegra_gpio_disable(tgi, offset);
 }

 static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)

```

I referenced the patch in `layers/meta-balena-jetson/recipes-kernel/linux/linux-tegra_%.bbappend` by appending it to the SRC\_URI

Since it is kind of urgend for us to fix this quickly i would highly appreciate, if someone could guide me into the right direction on how to reference the c lib correctly.

```auto
9+gitAUTOINC+3dcbed5d27-r0/recipe-sysroot-native/etc/quiltrc push' exited with 0 Output:
Applying patch 0001-spi-patch-linux-drivers-gpio-tegra.patch
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
|--- drivers/gpio/gpio-tegra.c
|+++ drivers/gpio/gpio-tegra_new.c
--------------------------
No file to patch. Skipping patch.

```

[Next page](https://forums.balena.io/t/jetson-nano-access-to-spi-device/59471.md?page=2)
