Using gpios with gpioset

which should be easy, but apparently is not?

So I have a LED attached to PJ05. I configure the pin in my DTS like this:

	gpio@2200000 {
		nice-led-pj5 {
			line-name = "nice-led-pj5";

When I boot, the LED turns on. Life is good. If I open /sys/kernel/debug/pinctrl/2430000.pinmux/pinconf-groups I get what I think is the correct configuration:

34 (gpio_aud0_pj5): 

If I do gpioinfo gpiochip0 all is good

line 77: unnamed "nice-led-pj5" output active-high [used]

Then I do this:

gpioset gpiochip0 77=1

(note the 1, it should stay on) and the gpio turns off (suffice to sat 77=0 still keeps it off). And I cannot turn it on anymore. Moreover, it disappears from gpioinfo:

line 77: unnamed unused output active-high

Now this happens for all my gpios, I can’t turn on any of them from the system. But since I’m clever, I figured out I can use the old gpio interface, right? Wrong:

echo 77 > /sys/class/gpio/export 
bash: echo: write error: Invalid argument

And the console says:

port_store: invalid GPIO 77

Note that the actual internal number for pj5 is 77, by a coincidence it is the same as the gpiod one.

sudo cat /sys/kernel/debug/pinctrl/2430000.pinmux/pinconf-pins | grep PJ5
pin 77 (GPIO_AUD0_PJ5):

As you may guess, this happens for all gpios, not only 77.

What is the obvious thing I’m missing?

[I’m running 32.3.1 and kernel 4.9]

hello EmbeddedRod,

please note that, there’s offset values you should check during the kernel init,
for example,

$ dmesg | grep "registered GPIOs"
[    0.478688] gpiochip_setup_dev: registered GPIOs 320 to 511 on device: gpiochip0 (tegra-gpio)
[    0.482675] gpiochip_setup_dev: registered GPIOs 256 to 319 on device: gpiochip1 (tegra-gpio-aon)

you might also refer to a python library that enables the use of Jetson’s GPIOs, Jetson-GPIO

Hi Jerry! Thanks for your response.
does Jetson-GPIO also work with gpios that are not exposed in the 40-pin header?

Ok so I figured out that PBB1 is gpio 397 in the legacy interface (BTW the documentation on how to calculate the offsets is wrong: You need to sum to the output of the formula the pin nr.), and it works using /sys/class/gpio/export and friends.
This said it does not work with the gpiod interface, and I can’t really use your python script because I need to use gpios from a C program, and sincerely I prefer not to be forced to call a python script with system(), or to use the old (and sincerely abhorrent) /sys/class/gpio interface.
What is weird is that gpiod can correctly read gpios set as input, I just can’t write to them.
Any help is appreciated.

EDIT: It would also be sincerely appreciated that there is an univocal system of numbering the gpios, since the current system is a nightmare. An innocuous looking pin, like PBB0 is called GPIO15, gpio488 and gpio168 depending which document, source, header or program output you are reading, it is unnecessarily confusing and complex.

1 Like

Here is a simple table you can use to look up the value for any of the Tegra GPIOS:

Thanks!! it is fantastic! much better than doing 21 * 8 + 320 + 1…

hello EmbeddedRod,

we had also revise documentation to fix the calculation formula.
please expect next public release version would include the update. thanks