Okay,
I have been doing the legwork to get familiar with all of the different GPIO pin mappings, so that I can further debug this by working directly with sysfs.
Let’s start from the beginning. I want to flip GPIO pin 12 on the 40-pin header. Looking at the classic reference: https://jetsonhacks.com/nvidia-jetson-xavier-nx-gpio-header-pinout/
I see that the pin I am using has the name I2S0_SCLK. Now heading over to the pinmux spreadsheet, I see that I2S0_SCLK corresponds to GPIO3_PT.05.
This is where I think I may be doing something wrong / missing something. As this next step is how you calculate the GPIO number used by sysfs.
Port T has a multiplier of 19 according to tegra194-gpio.h found here: linux/include/dt-bindings/gpio/tegra194-gpio.h at master · torvalds/linux · GitHub
#define TEGRA194_MAIN_GPIO_PORT_T 19
So the base offset of my header pin 12 should be:
(19 * 8) + 5 = 157
Now we need to add in offset added by the kernel, which we find using:
sudo dmesg | grep "registered GPIOs"
The result on my Xavier NX dev kit is this:
dev@tegra-ubuntu:~$ sudo dmesg | grep "registered GPIOs"
[ 3.091638] gpiochip0: registered GPIOs 504 to 511 on max77620-gpio
[ 5.907877] gpiochip1: registered GPIOs 335 to 503 on tegra194-gpio
[ 5.909870] gpiochip2: registered GPIOs 305 to 334 on tegra194-gpio-aon
Which leads me to believe I need to add 335 to this number I calculated earlier, my justification for picking the middle tegra194-gpio range is that Port T is part of the MAIN GPIO controller.
So my final number comes out to:
157 + 335 = 492. This is notably very different from what is in our guide here: https://jetsonhacks.com/nvidia-jetson-xavier-nx-gpio-header-pinout/, which cites 445 as the magic number.
Could somebody shed some light on what I may be doing wrong here?
Also, performing
echo 445 > /sys/class/gpio/export
Creates a node in /sys/class/gpio/ called PR.02, which seems to not be correct either.
Performing
echo 492 > /sys/class/gpio/export
Creates a node called PZ.00, which is also not what I’d expect.
Configuring the direction of these two nodes to out and writing a value of 1 does NOT cause any change in the pin 12 on the 40-pin header.
Could use some insight, thanks in advance.
EDIT:
Through trial and error I figured out that the correct sysfs GPIO number for my pin is 462.
Performing:
100 echo 462 > /sys/class/gpio/export
101 cd /sys/class/gpio/
102 cd PT.05/
104 cat direction
105 echo out > direction
106 cat value
107 echo 1 > value
108 echo 0 > value
109 echo 1 > value
110 echo 0 > value
Behaves exactly how I’d expect and allows me to toggle the GPIO pin up and down, with normal 3.3V high and 0v low. ALSO, after doing this I tried to run the simple_out.py example again and got a Device or Resource busy exception. Unexporting the pin with:
echo 462 > /sys/class/gpio/unexport
and re-running simple_out.py makes it work perfectly!
However I am still in need of some clarification on the correct way to reach this 462 number. Thank you.