Jetson Nano access to SPI device

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 project that describes how the device tree can be modified.
Furthermore eLinux describes it in more detail for the similar TX1 station

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 :slight_smile:

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

Hmm, i will flash a fresh image provided by 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

SUPERVISOR VERSION: 10.3.7
OS VERSION:         balenaOS 2.45.1+rev3

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

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?

Sadly it did not work.

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

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.

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 :confused:

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

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

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

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

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

@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.

I created a new forum entry for this challenge.

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

Here is the pull request

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. :slight_smile:

@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.

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.

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.