Xavier NX - GPIO character device interface

Hi,

I am trying to use the character device based interface for configuring and controlling GPIOs of the Xavier NX. I am using the JetPack 4.6.2 (L4T R32.7.2).

For prototyping I use the command line tool provided with libgpiod. I am trying to set pin 114 (signal name = CAM0_PWDN, ball name = SOC_GPIO04):

sudo gpioset gpiochip0 114=1

But this doesn’t work. I am able to set the pin using the deprecated sysfs interface, that is why I believe I am using the wrong GPIO line offset.

So my question is:

  • What is the correct GPIO mapping for the character device interface?

Thanks in advance!
Bruno

Hi bruno.kempf,

Are you using the devkit or custom board for Xavier NX?
What’s your Jetpack version in use?

Please refer to the following thread for the usage of gpiod.
Unable to access GPIO in the latest L4T 35.3.1 - #23 by lhoang

You could run the following command first.

$ sudo gpiodetect

This contains all the mapping

for the 40-pin header for the jetson official dev kits

1 Like

Hi KevinFFF,

I am using JetPack 4.6.2 (L4T R32.7.2) and I am using a custom carrier board. As I mentioned above I am able to control the GPIO using the sysfs interface. Thus I exclude a hardware issue.

I already ran the sudo gpiodetect command. Unfortunately, currently I don’t have access to the hardware to post the output of this command.

Also I don’t know how the referenced link helps to fix the described issue. As I mentioned I don’t have an issue with the sysfs interface. Using the sysfs interface works but I need to switch to the character device interface and somehow I am unable to control the GPIOs using the gpiod CLI tool (which utilizes the character device interface).
Could you explain what the referenced post contains that you think is useful for my issue? Should I test the jetson-gpio python library - just to see if it works with this library (I need to implement my application in C/C++, so the python library is not suitable as a solution)?

Thanks
Bruno

Hi Ihoang,

thanks for the reference. I will take a look at the mapping and see if I can use it for controlling the GPIOs via the gpiod CLI tool.

One question regarding the image below:

  • Is the Xavier NX = JETSON_XAVIER or JETSON_NX?

image

Thanks
Bruno

Please just start from sudo gpiodetect and refer to the instruction to control GPIO in runtime.
If you want to control GPIO in C/C++, please just refer to gpiolib.c.

JETSON_NX is Jetson Xavier NX, which is also Xavier NX you mean
JETSON_XAVIER is Jetson Xavier AGX

Hi KevinFFF,

I will continue with this topic on monday. Thanks so far.

If you use custom carrier board, the mapping above might not be correct. You may ask the custom carrier board’s manufacturer for the specification sheet

Hi @lhoang,

maybe my question was not precise enough and a bit confusing because I used the term “mapping”. Actually I am not interested in the mapping of SoC pins to 40-pin header.

What I would like to know are the numbers I have to use with the GPIO character device interface. For example if I want to use the gpiod CLI-Tool to set the level of SoC pin 114 (the number of the CVM/CVB connector pin, signal name = CAM0_PWDN).
What is the number I have to use with the GPIO character device interface to set CAM0_PWDN pin?
Is this the correct way to use the gpiod CLI-Tool to set the CAM0_PWDN?

sudo gpioset gpiochip0 114=1

I started my attempt to implement GPIO control using the GPIO character device interface based on this post Control GPIO using the new Linux user space GPIO API (lxsang.me) which is also referenced in the post above (Xavier NX - GPIO character device interface - #3 by KevinFFF).
According to the tutorial the bash-command above should set the pin 114 (CAM0_PWDN) of the Xavier NX SoC to HIGH. But nothing happens when I execute this command.
When I use the sysfs interface it works fine (of course with the correct GPIO number according to the formula GPIO = group_offset + port * 8 + pin = 288 + 15 * 8 + 4 = 412).

Why does it work with the sysfs interface but not with the character device interface?
Am I using the wrong number with the character device interface?

Best regards
Bruno

No it is not the correct number. This is how you find the number.

First, Download Jetson Xavier NX Pinmux Table from Jetson Download Center
Second, find the pin you want to control and get the corresponding GPIO name; in your case it is “GPIO3_PP.04”
Third, run sudo gpioinfo and find PP.04. you can see that it is line 96 on gpiochip0. That is the combination you should use.

1 Like

Hi @lhoang,

this is exactly the information I was looking for. Unfortunately, using

sudo gpioset gpiochip0 96=1

and

sudo gpioset gpiochip0 96=0

doesn’t operate the pin.
However using this commands

echo 412 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio412/direction
echo 1 > /sys/class/gpio/gpio412/value
echo 0 > /sys/class/gpio/gpio412/value

Operates the pin as expected.

Also, I examined the output of gpioinfo before and I don’t get any PP,04 or any other GPIO naming. Only very few GPIO lines have a description:

user@jetson:~$ sudo gpioinfo
gpiochip0 - 224 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed       unused   input  active-high
        line   3:      unnamed       unused   input  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused   input  active-high
        line   6:      unnamed       unused   input  active-high
        line   7:      unnamed       unused   input  active-high
        line   8:      unnamed       unused   input  active-high
        line   9:      unnamed       unused   input  active-high
        line  10:      unnamed       unused   input  active-high
        line  11:      unnamed       unused   input  active-high
        line  12:      unnamed       unused   input  active-high
        line  13:      unnamed       unused   input  active-high
        line  14:      unnamed       unused   input  active-high
        line  15:      unnamed       unused   input  active-high
        line  16:      unnamed       unused   input  active-high
        line  17:      unnamed       unused   input  active-high
        line  18:      unnamed       unused   input  active-high
        line  19:      unnamed       unused   input  active-high
        line  20:      unnamed       unused   input  active-high
        line  21:      unnamed       unused   input  active-high
        line  22:      unnamed       unused   input  active-high
        line  23:      unnamed       unused   input  active-high
        line  24:      unnamed       unused   input  active-high
        line  25:      unnamed       unused   input  active-high
        line  26:      unnamed       unused   input  active-high
        line  27:      unnamed       unused   input  active-high
        line  28:      unnamed       unused   input  active-high
        line  29:      unnamed       unused   input  active-high
        line  30:      unnamed       unused   input  active-high
        line  31:      unnamed       unused   input  active-high
        line  32:      unnamed       unused   input  active-high
        line  33:      unnamed       unused   input  active-high
        line  34:      unnamed       unused   input  active-high
        line  35:      unnamed       unused   input  active-high
        line  36:      unnamed       unused   input  active-high
        line  37:      unnamed       unused   input  active-high
        line  38:      unnamed       unused   input  active-high
        line  39:      unnamed       unused   input  active-high
        line  40:      unnamed       unused   input  active-high
        line  41:      unnamed       unused   input  active-high
        line  42:      unnamed       unused   input  active-high
        line  43:      unnamed       unused   input  active-high
        line  44:      unnamed       unused   input  active-high
        line  45:      unnamed       unused   input  active-high
        line  46:      unnamed       unused   input  active-high
        line  47:      unnamed       unused   input  active-high
        line  48:      unnamed "force-recovery" input active-low [used]
        line  49:      unnamed       unused   input  active-high
        line  50:      unnamed "vdd-sdmmc1-sw" output active-high [used]
        line  51:      unnamed       unused   input  active-high
        line  52:      unnamed       unused   input  active-high
        line  53:      unnamed       unused   input  active-high
        line  54:      unnamed       unused   input  active-high
        line  55:      unnamed         "cd"   input  active-high [used]
        line  56:      unnamed       unused   input  active-high
        line  57:      unnamed       unused   input  active-high
        line  58:      unnamed       unused   input  active-high
        line  59:      unnamed       unused   input  active-high
        line  60:      unnamed       unused   input  active-high
        line  61:      unnamed       unused   input  active-high
        line  62:      unnamed       unused   input  active-high
        line  63:      unnamed       unused   input  active-high
        line  64:      unnamed       unused   input  active-high
        line  65:      unnamed       unused   input  active-high
        line  66:      unnamed       unused   input  active-high
        line  67:      unnamed       unused   input  active-high
        line  68:      unnamed       unused   input  active-high
        line  69:      unnamed       unused   input  active-high
        line  70:      unnamed       unused   input  active-high
        line  71:      unnamed       unused   input  active-high
        line  72:      unnamed       unused   input  active-high
        line  73:      unnamed       unused   input  active-high
        line  74:      unnamed       unused   input  active-high
        line  75:      unnamed       unused   input  active-high
        line  76:      unnamed       unused   input  active-high
        line  77:      unnamed       unused   input  active-high
        line  78:      unnamed       unused   input  active-high
        line  79:      unnamed       unused   input  active-high
        line  80:      unnamed       unused   input  active-high
        line  81:      unnamed       unused   input  active-high
        line  82:      unnamed       unused   input  active-high
        line  83:      unnamed       unused   input  active-high
        line  84:      unnamed       unused   input  active-high
        line  85:      unnamed       unused   input  active-high
        line  86:      unnamed       unused   input  active-high
        line  87:      unnamed       unused   input  active-high
        line  88:      unnamed       unused   input  active-high
        line  89:      unnamed       unused   input  active-high
        line  90:      unnamed  "pcie_wake"   input  active-high [used]
        line  91:      unnamed       unused   input  active-high
        line  92:      unnamed       unused   input  active-high
        line  93:      unnamed       unused   input  active-high
        line  94:      unnamed       unused   input  active-high
        line  95:      unnamed       unused   input  active-high
        line  96:      unnamed       unused   input  active-high
        line  97:      unnamed "hdmi2.0_hpd" input active-high [used]
        line  98:      unnamed       unused   input  active-high
        line  99:      unnamed       unused   input  active-high
        line 100:      unnamed       unused   input  active-high
        line 101:      unnamed       unused   input  active-high
        line 102:      unnamed       unused   input  active-high
        line 103:      unnamed       unused   input  active-high
        line 104:      unnamed "avdd-cam-2v8" output active-high [used]
        line 105:     "GPIO13"       unused   input  active-high
        line 106:      unnamed       unused   input  active-high
        line 107:      unnamed       unused   input  active-high
        line 108:      unnamed       unused   input  active-high
        line 109:      unnamed       unused   input  active-high
        line 110:      unnamed       unused   input  active-high
        line 111:      unnamed       unused   input  active-high
        line 112:      unnamed       unused   input  active-high
        line 113:      unnamed       unused   input  active-high
        line 114:      unnamed       unused   input  active-high
        line 115:      unnamed       unused   input  active-high
        line 116:      unnamed       unused   input  active-high
        line 117:      unnamed       unused   input  active-high
        line 118:      unnamed       unused   input  active-high
        line 119:      unnamed       unused   input  active-high
        line 120:      unnamed       unused   input  active-high
        line 121:      unnamed       unused   input  active-high
        line 122:      unnamed       unused   input  active-high
        line 123:      unnamed       unused   input  active-high
        line 124:      unnamed       unused   input  active-high
        line 125:      unnamed       unused   input  active-high
        line 126:      unnamed       unused   input  active-high
        line 127:      unnamed       unused   input  active-high
        line 128:      unnamed       unused   input  active-high
        line 129:      unnamed       unused   input  active-high
        line 130:      unnamed       unused   input  active-high
        line 131:      unnamed       unused   input  active-high
        line 132:      unnamed       unused   input  active-high
        line 133:     "GPIO01"       unused   input  active-high
        line 134:     "GPIO11"       unused   input  active-high
        line 135:      unnamed       unused   input  active-high
        line 136:     "GPIO07"       unused   input  active-high
        line 137:      unnamed "eqos_phy_reset" output active-high [used]
        line 138:      unnamed       unused   input  active-high
        line 139:      unnamed       unused   input  active-high
        line 140:  "UART1_RTS"       unused   input  active-high
        line 141:  "UART1_CTS"       unused   input  active-high
        line 142:      unnamed       unused   input  active-high
        line 143:      unnamed       unused   input  active-high
        line 144:      unnamed       unused   input  active-high
        line 145:      unnamed       unused   input  active-high
        line 146:      unnamed       unused   input  active-high
        line 147:      unnamed       unused   input  active-high
        line 148:     "GPIO09"       unused   input  active-high
        line 149:      unnamed       unused   input  active-high
        line 150:      unnamed       unused   input  active-high
        line 151:      unnamed       unused   input  active-high
        line 152:      unnamed       unused   input  active-high
        line 153:      unnamed       unused   input  active-high
        line 154:      unnamed       unused   input  active-high
        line 155:      unnamed       unused   input  active-high
        line 156:      unnamed       unused   input  active-high
        line 157:  "I2S0_SCLK"       unused   input  active-high
        line 158:  "I2S0_DOUT"       unused   input  active-high
        line 159:   "I2S0_DIN"       unused   input  active-high
        line 160:    "I2S0_FS"       unused   input  active-high
        line 161:      unnamed       unused   input  active-high
        line 162:      unnamed       unused   input  active-high
        line 163:      unnamed       unused   input  active-high
        line 164:      unnamed       unused   input  active-high
        line 165:      unnamed       unused   input  active-high
        line 166:      unnamed       unused   input  active-high
        line 167:      unnamed       unused   input  active-high
        line 168:      unnamed       unused   input  active-high
        line 169:      unnamed       unused   input  active-high
        line 170:      unnamed       unused   input  active-high
        line 171:      unnamed       unused   input  active-high
        line 172:      unnamed       unused   input  active-high
        line 173:      unnamed       unused   input  active-high
        line 174:      unnamed       unused   input  active-high
        line 175:      unnamed       unused   input  active-high
        line 176:      unnamed       unused   input  active-high
        line 177:      unnamed       unused   input  active-high
        line 178:      unnamed       unused   input  active-high
        line 179:      unnamed       unused   input  active-high
        line 180:      unnamed       unused   input  active-high
        line 181:      unnamed       unused   input  active-high
        line 182:      unnamed       unused   input  active-high
        line 183:      unnamed       unused   input  active-high
        line 184:      unnamed       unused   input  active-high
        line 185:      unnamed       unused   input  active-high
        line 186:      unnamed       unused   input  active-high
        line 187:      unnamed       unused   input  active-high
        line 188:      unnamed       unused   input  active-high
        line 189:      unnamed       unused   input  active-high
        line 190:      unnamed       unused   input  active-high
        line 191:      unnamed       unused   input  active-high
        line 192:   "SPI1_SCK"       unused   input  active-high
        line 193:  "SPI1_MISO"       unused   input  active-high
        line 194:  "SPI1_MOSI"       unused   input  active-high
        line 195:   "SPI1_CS0"       unused   input  active-high
        line 196:   "SPI1_CS1"       unused   input  active-high
        line 197:      unnamed       unused   input  active-high
        line 198:      unnamed       unused   input  active-high
        line 199:      unnamed       unused   input  active-high
        line 200:      unnamed       unused   input  active-high
        line 201:      unnamed "external-connection:extcon@1" input active-high [used]
        line 202:      unnamed       unused   input  active-high
        line 203:   "SPI0_SCK"       unused   input  active-high
        line 204:  "SPI0_MISO"       unused   input  active-high
        line 205:  "SPI0_MOSI"       unused   input  active-high
        line 206:   "SPI0_CS0"       unused   input  active-high
        line 207:   "SPI0_CS1"       unused   input  active-high
        line 208:      unnamed       unused   input  active-high
        line 209:      unnamed       unused   input  active-high
        line 210:      unnamed       unused   input  active-high
        line 211:      unnamed       unused   input  active-high
        line 212:      unnamed       unused   input  active-high
        line 213:      unnamed       unused   input  active-high
        line 214:      unnamed       unused   input  active-high
        line 215:      unnamed       unused   input  active-high
        line 216:      unnamed       unused   input  active-high
        line 217:      unnamed       unused   input  active-high
        line 218:      unnamed       unused   input  active-high
        line 219:      unnamed       unused   input  active-high
        line 220:      unnamed       unused   input  active-high
        line 221:      unnamed       unused   input  active-high
        line 222:      unnamed       unused   input  active-high
        line 223:      unnamed       unused   input  active-high
gpiochip1 - 40 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed       unused   input  active-high
        line   3:      unnamed       unused   input  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused   input  active-high
        line   6:      unnamed       unused   input  active-high
        line   7:      unnamed       unused   input  active-high
        line   8:      unnamed       unused   input  active-high
        line   9:      unnamed       unused   input  active-high
        line  10:      unnamed       unused   input  active-high
        line  11:      unnamed       unused   input  active-high
        line  12:      unnamed       unused   input  active-high
        line  13:      unnamed       unused   input  active-high
        line  14:      unnamed       unused   input  active-high
        line  15:      unnamed       unused   input  active-high
        line  16:      unnamed "w-disable2"  output   active-low [used]
        line  17:      unnamed          "?"  output  active-high [used]
        line  18:      unnamed "w-disable1"  output   active-low [used]
        line  19:      unnamed       unused   input  active-high
        line  20:     "GPIO12"       unused   input  active-high
        line  21:      unnamed       unused   input  active-high
        line  22:      unnamed       unused   input  active-high
        line  23:      unnamed       unused   input  active-high
        line  24:      unnamed       unused   input  active-high
        line  25:      unnamed       unused   input  active-high
        line  26:      unnamed       unused   input  active-high
        line  27:      unnamed       unused   input  active-high
        line  28:      unnamed       unused   input  active-high
        line  29:      unnamed       unused   input  active-high
        line  30:      unnamed       unused   input  active-high
        line  31:      unnamed       unused   input  active-high
        line  32:      unnamed       unused   input  active-high
        line  33:      unnamed       unused   input  active-high
        line  34:      unnamed       unused   input  active-high
        line  35:      unnamed       unused   input  active-high
        line  36:      unnamed  "power-key"   input   active-low [used]
        line  37:      unnamed       unused   input  active-high
        line  38:      unnamed       unused   input  active-high
        line  39:      unnamed       unused   input  active-high
gpiochip2 - 8 lines:
        line   0:      unnamed       unused   input  active-high
        line   1:      unnamed       unused   input  active-high
        line   2:      unnamed       unused   input  active-high
        line   3:      unnamed       unused   input  active-high
        line   4:      unnamed       unused   input  active-high
        line   5:      unnamed       unused   input  active-high
        line   6:      unnamed "gpio_default" output active-high [used]
        line   7:      unnamed "gpio_default" output active-high [used]

As you can see there are no references where I could deduce the information from to find the right number for the corresponding pin.
I didn’t change the pinmux configuration, so I don’t understand why this information is missing.
@lhoang Did you use a certain pinmux configuration or is it the default one shipped with the JetPack 4.6.2?

Best regards
Bruno

Ok I see. That information is only available in newer kernel which I used before. Can you use number 124
then? it is 412 minus the group offset

2 Likes

Hi @lhoang,

unfortunately it is not working with number 124. The first image shows the result when I tried to set the GPIO. So it actually doesn’t do anything. Not only the measurments show that the GPIOs don’t switch, but also the read back using gpioget.

But I found that the number 124 must be correct for the pin I want to control. This is shown by the second image. The first three lines use the sysfs interface to setup the GPIO and set the pin to HIGH. The fourth line tries to read the value with number 96, the fifth line tries to read the value with number 124. As can be seen in the image the GPIO with number 124 is “busy”. After I unexport the GPIO using the sysfs interface I can read back the value using the gpioget command.

Unfortunately, just like the gpioset, the gpioget command is actually not working as it returns the same value independent of the actual value of the GPIO.

Best regards
Bruno

gpioget does not get the current value set my gpioset but turn it into an input pin and read it from the outside.
For gpioset, you must use --mode=wait so that the gpio is continuously driven .

Please read this manual gpioset(1) — gpiod — Debian experimental — Debian Manpages

1 Like

Hi @lhoang,

sorry for bothering you with this trivial error. With the mode=wait I am able to measure the correct GPIO operation.

Thank you!

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