Jetson Nano and SPI - How to Actually fix it with an SD Card Image

I know there have been a lot of threads about this issue here, but as far as I know there is no fix that doesn’t involve flashing the Nano from an Ubuntu Desktop PC.
That didn’t work for me, so I tried to solve it myself and actually succeeded.

I modified the GPIO driver to fix this SPI issue and uploaded the code changes, as well as a ready to download ISO file in this github repository:

That Iso also makes it easier to access both UART ports and makes the I2C port a bit more reliable.

If any nvidia devs read this, you are of course welcome to include these changes in the official image.

Hopefully that will help some of you, it took me quite some time to figure all that out

2 Likes

Let me try this and let you know

Hi heyho123,

Thanks for your sharing.

It seems you modify the GPIO driver for Tegra.
You add tegra_gpio_is_gpio_force_disabled() to check if specific GPIO are disabled.

May I know what’s the SPI issue you hit on Jetson Nano?

Sorry for the late reply.
I mean the SPI issue that is for example discussed here:

or here:

There are many more threads here that describe the same issue. SPI is basically not working because the GPIO driver uses the SPI pins.

What I found out is that very early in the boot process, before the sd card image is read, the GPIO driver marks the SPI pins as GPIO. And the official sd card just assumes that the SPI pins are available, even if GPIO is disabled in the settings. The GPIO driver on the sd card just assumes that GPIO is disabled on all the pins when it boots, so it doesn’t bother to disable GPIO.
That’s why all the proposed fixes, apart from manually flashing without a sd card, don’t work.

What I did to fix this is to explicitely disable GPIO on the SPI pins in the GPIO driver on boot up. That’s the following code in tegra_gpio_probe:

	// Disable gpios that might block SPI or I2S.
	// These somehow get enabled in the early stages of booting and if we don't
	// disable them now, SPI becomes unusable.
	for (gpio = 0; gpio < tgi->gc.ngpio; gpio++) {
		int b = GPIO_BANK(gpio);
		int p = GPIO_PORT(gpio);
		u32 mask = BIT(GPIO_BIT(gpio));
		unsigned long flags;
		u32 enabled;

		if (!tegra_gpio_is_gpio_force_disabled(gpio))
			continue;

		bank = &tgi->bank_info[b];
		spin_lock_irqsave(&bank->gpio_lock[p], flags);
		enabled = tegra_gpio_readl(tgi, GPIO_CNF(tgi, gpio)) & mask;
		spin_unlock_irqrestore(&bank->gpio_lock[p], flags);

		if (enabled) {
			dev_err(&pdev->dev, "Disable GPIO %d", gpio);
			tegra_gpio_disable(tgi, gpio);
		}
	}

This is a bit of a hack, what you really want to do is to stop the first GPIO driver from blocking the SPI pins, but you cannot do that with an sd card image.

@bahie3398
Did it work for you? Let me know if there were any hurdles to use this.

To verify SPI on Jetson Nano, please refer to steps of our verification in Jetson Nano SPI Bus Not Working - #10 by KevinFFF

You can also run the following command to check GPIO pin state.

$ sudo cat /sys/kernel/debug/tegra_gpio
$ sudo cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi

Not sure what you are replying to there.
The guide you link to requires flashing the Jetson Nano, a quite involved process which I wanted to avoid.

The link I provided in the first post should fix this issue for anyone who stumbles upon this:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.