Sysfs gpio access error

Hi,
I am trying to use GPIO on Xavier NX, and following the slide 35 in here:

But it fails at the very first step:
echo 38 > /sys/class/gpio/export

fails with the following message:
bash: echo: write error: Invalid argument

I am using Jetpack 4.5.1. Has something changes since when the presentation was made?

Thanks
Jan

hello jan.juran,

that’s wrong GPIO number for Xavier NX series.
there’s offsets during kernel init stage, please check $ dmesg | grep "registered GPIOs" for the allocated GPIOs.
you should also see tegra194-gpio.h for the port index and calculation formula for reference.
thanks

Hm, that’s confusing. I thought NX has the same carrier board as Nano.
OK, will have a look. Thanks.

hello jan.juran,

they’re different modules,
please check GPIO header files for the port index and calculation formula.
for example,
Jetson TX1 and Nano series, tegra-gpio.h
Jetson TX2 series, tegra186-gpio.h
Jetson AGX Xavier and Xavier NX series, tegra194-gpio.h

Hi, thanks. I am beginning to understand.

In the header file, it says the formula is this:

#define TEGRA194_MAIN_GPIO(port, offset) \
	((TEGRA194_MAIN_GPIO_PORT_##port * 8) + offset)

OK, offset probably means the actual pin number of the physical GPIO header.

But how do I find out the port. That’s absolutely not clear to me.

I’ve been able to find this:

which says that pin 33 should be gpio393. After subtracting the base which in my case seems to be 288 (dmesg output you mentioned) and subtracting the pin offset (33) I get 72. Divided by 8 I get 9 which maps to port J (looking again at the header file). But how would I find out the port if I didn’t know the final result in the end?

In my case the aforementioned picture is actually all I need, but maybe just for future generations… :-)

hello jan.juran,

let’s taking pin-33 for example, it’s GPIO13, GPIO3_PN.01,
btw, it’s pinmux spreadsheets to include the detail signal name and the pin muxing. please searching for GPIO13 to find its GPIO signal.

for this GPIO3_PN.01,
you should consider GPIO3_P for mapping to its port index, whereas the port index is N; offset is 1.
then, checking the header file, tegra194-gpio.h.

#define TEGRA194_MAIN_GPIO_PORT_N 13
...
#define TEGRA194_MAIN_GPIO(port, offset) \
  	((TEGRA194_MAIN_GPIO_PORT_##port * 8) + offset)

the gpio numbers is… (13 * 8 + 1) + 288 = 393, same as the external page mentioned, gpio393

Oh, I see. Thanks for the explanation, now it makes sense.

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