kdb342: Using GPIO on Connect Tech Jetson Xavier/TX2/TX1 Carriers

Introduction

Using the Jetson Xavier/TX2/TX1 GPIO pins is primarily done using the Linux sysfs (for pins directly connected to Jetson) or I2C read/writes (for pins using I2C GPIO expanders). The “pin# (source)” column of the table has details about which GPIO pins are sourced directly from the Jetson and which ones use an I2C GPIO expander for your carrier.

Note: Many of the commands shown in this guide will require you to be the root user or to use sudo

GPIO TX1 Reference Table

Part NumberBoard NamePin # (source)*Carrier Designator
(Header-Pin#)
Voltage Levelsysfs #In/out (default)PU/PD (ohms)Device Tree Name
ASG001, ASG004AstroH13 (TX1)P4-11.8187inPU (100K)als_prox_int_px3
G14 (TX1)P4-31.8186inPU (100K)motion_int_px2
A22 (TX1)P4-51.889inPU (100K)pl1
A23 (TX1)P4-71.8202inPU (100K)pz2
ASG002ElroyH13 (TX1)P5-121.8187inPU (100K)als_prox_int_px3
G14 (TX1)P5-141.8186inPU (100K)motion_int_px2
A22 (TX1)P5-161.889inPU (100K)pl1
A23 (TX1)P5-181.8202inPU (100K)pz2
ASG003, ASG016Orbitty, QuasarH13 (TX1)P4-73.3187inPU (100K)als_prox_int_px3
G14 (TX1)P4-83.3186inPU (100K)motion_int_px2
A22 (TX1)P4-93.389inPU (100K)pl1
A23 (TX1)P4-103.3202inPU (100K)pz2
ESG503, ASG005RudiP00 (TCA9539@74)I/O -53.3488inNoneTBD
P01 (TCA9539@74)I/O -63.3489inNoneTBD
P02 (TCA9539@74)I/O -73.3490inNoneTBD
P03 (TCA9539@74)I/O -83.3491inNoneTBD
ASG006SpacelyP00 (TCA9539@77)P13-153.3472inNoneTBD
P01 (TCA9539@77)P13-163.3473inNoneTBD
P02 (TCA9539@77)P13-133.3474inNoneTBD
P03 (TCA9539@77)P13-143.3475inNoneTBD
P04 (TCA9539@77)P13-113.3476inNoneTBD
P05 (TCA9539@77)P13-123.3477inNoneTBD
P06 (TCA9539@77)P13-93.3478inNoneTBD
P07 (TCA9539@77)P13-103.3479inNoneTBD
P10 (TCA9539@77)P13-73.3480inNoneTBD
P11 (TCA9539@77)P13-83.3481inNoneTBD
P12 (TCA9539@77)P13-53.3482inNoneTBD
P13 (TCA9539@77)P13-63.3483inNoneTBD
P14 (TCA9539@77)P13-33.3484inNoneTBD
P15 (TCA9539@77)P13-43.3485inNoneTBD
P16 (TCA9539@77)P13-13.3486inNoneTBD
P17 (TCA9539@77)P13-23.3487inNoneTBD
ASG007CogswellP0 (XRA1200@20)P7-33.3496inNoneTBD
P1 (XRA1200@20)P7-13.3497inNoneTBD
P2 (XRA1200@20)P7-43.3498inNoneTBD
P3 (XRA1200@20)P7-23.3499inNoneTBD
ASG008SprocketH13 (TX1)P2-73.3187inPU (100K)als_prox_int_px3
G14 (TX1)P2-83.3186inPU (100K)motion_int_px2
A22 (TX1)P2-93.389inPU (100K)pl1
A23 (TX1)P2-103.3202inPU (100K)pz2
* Format for GPIOs directly from the TX1 :
[A#] (TX1), where the A# is the TX1 Module Pin #;
Format for the GPIOs from I2C Expanders:
[P##] ([Part#]@[I2C##])
Where P## is the Expander's GPIO #, Part# is the I2C expander part # and @I2C## is the Expander's I2C Address

GPIO TX2 Reference Table

Part NumberBoard NamePin # (source)*Carrier Designator
(Header-Pin#)
Voltage Levelsysfs #In/out (default)PU/PD (ohms)Device Tree Name
ASG001, ASG004AstroH13 P4-11.8388inPU (20K)gpio_pq4_pi4
G14 P4-31.8298inPU (20K)can_gpio2_paa2
A22 P4-51.8480inPU (100K)gpio_mdm7_py6
A23 P4-71.8486inPU (100K)gpio_mdm1_py0
ASG002ElroyH13 P5-121.8388inPU (20K)gpio_pq4_pi4
G14 P5-141.8298inPU (20K)can_gpio2_paa2
A22 P5-161.8480inPU (100K)gpio_mdm7_py6
A23 P5-181.8486inPU (100K)gpio_mdm1_py0
ASG003, ASG016Orbitty, QuasarH13P4-73.3388inPU (20K)gpio_pq4_pi4
G14 P4-83.3298inPU (20K)can_gpio2_paa2
A22 P4-93.3480inPU (100K)gpio_mdm7_py6
A23 P4-103.3486inPU (100K)gpio_mdm1_py0
ESG503, ASG005RudiP00 (TCA9539@74)I/O -53.3232inNoneTBD
P01 (TCA9539@74)I/O -63.3233inNoneTBD
P02 (TCA9539@74)I/O -73.3234inNoneTBD
P03 (TCA9539@74)I/O -83.3235inNoneTBD
ASG006SpacelyP00 (TCA9539@77)P13-153.3216inNoneTBD
P01 (TCA9539@77)P13-163.3217inNoneTBD
P02 (TCA9539@77)P13-133.3218inNoneTBD
P03 (TCA9539@77)P13-143.3219inNoneTBD
P04 (TCA9539@77)P13-113.3220inNoneTBD
P05 (TCA9539@77)P13-123.3221inNoneTBD
P06 (TCA9539@77)P13-93.3222inNoneTBD
P07 (TCA9539@77)P13-103.3223inNoneTBD
P10 (TCA9539@77)P13-73.3224inNoneTBD
P11 (TCA9539@77)P13-83.3225inNoneTBD
P12 (TCA9539@77)P13-53.3226inNoneTBD
P13 (TCA9539@77)P13-63.3227inNoneTBD
P14 (TCA9539@77)P13-33.3228inNoneTBD
P15 (TCA9539@77)P13-43.3229inNoneTBD
P16 (TCA9539@77)P13-13.3230inNoneTBD
P17 (TCA9539@77)P13-23.3231inNoneTBD
ASG007CogswellP0 (XRA1200@20)P7-33.3240inNoneTBD
P1 (XRA1200@20)P7-13.3241inNoneTBD
P2 (XRA1200@20)P7-43.3242inNoneTBD
P3 (XRA1200@20)P7-23.3243inNoneTBD
ASG008SprocketH13 P2-73.3388inPU (20K)gpio_pq4_pi4
G14 P2-83.3298inPU (20K)can_gpio2_paa2
A22 P2-93.3480inPU (100K)gpio_mdm7_py6
A23 P2-103.3486inPU (100K)gpio_mdm1_py0
* Format for GPIOs directly from the TX2 :
[A#] (TX1), where the A# is the TX1 Module Pin #;
Format for the GPIOs from I2C Expanders:
[P##] ([Part#]@[I2C##])
Where P## is the Expander's GPIO #, Part# is the I2C expander part # and @I2C## is the Expander's I2C Address

GPIO Xavier Reference Table

Part NumberBoard NamePin # (source)*Carrier Designator
(Header-Pin#)
Voltage Levelsysfs #In/out (default)PU/PD (ohms)Device Tree Name
AGX001MimicE10TX2-GPIO121.8V440TBDTBDTBD
G7TX2-GPIO131.8V443TBDTBDTBD
L15TX2-GPIO101.8V444TBDTBDTBD
A54TX2-GPIO111.8V417TBDTBDTBD
K56TX2-GPIO151.8VTBDTBDTBDTBD
G55TX2-GPIO171.8VTBDTBDTBDTBD
J51TX2-GPIO141.8VTBDTBDTBDTBD
H51TX2-GPIO161.8VTBDTBDTBDTBD
H52TX2-GPIO181.8VTBDTBDTBDTBD
A7TX2-GPIO91.8V412BiDirTBDTBD
J55TX2-GPIO81.8V438BiDirTBDTBD
C55TX2-GPIO_EXP0_INT1.8V414BiDirTBDTBD
L50TX2-GPIO_EXP1_INT1.8V344BiDirTBDTBD
AGX101RogueE10P3-133.3V440InPU (100k)SOC_GPIO33_PT0
G7P3-153.3V443InPU (100k)DAP3_DIN_PT3
L15P3-173.3V444InPU (100k)DAP3_FS_PT3
A54P3-193.3V417InPD (100k)SOC_GPIO21_PQ1
* Format for GPIOs directly from the Xavier :
[A#] (TX1), where the A# is the Xavier Module Pin #;
Format for the GPIOs from I2C Expanders:
[P##] ([Part#]@[I2C##])
Where P## is the Expander's GPIO #, Part# is the I2C expander part # and @I2C## is the Expander's I2C Address

GPIO Sentry-X Reference Table

Part NumberBoard NamePin # (source)Designator (PC Style D-SUB 44)Designator (Fischer MiniMax)Voltage Levelsysfs #Sentry X Function
SGX001Sentry-XE59J4 pin 29J5 pin 15V253ZEROIZE
F59InternalInternal1.8V254LED_CTL0
B62InternalInternal1.8V256LED_CTL1
C61InternalInternal1.8V257LED_CTL2
B8J4 pin 34J5 pin 225V437GPO0
E10J4 pin 33J5 pin 115V440GPO1
G7J4 pin 32J5 pin 125V443GPO2
L15J4 pin 31J5 pin 245V444GPO3
F10J4 pin 4J5 pin 165V445GPI0
F9J4 pin 3J5 pin 75V446GPI1
A54J4 pin 2J5 pin 85V417GPI2
C55J4 pin 1J5 pin 185V420GPI3
K56InternalInternal1.8V423SERIAL1_MODE (0=RS232 or 1=RS485)
A58InternalInternal1.8V291SERIAL1_DUPLEX (0=Full Duplex, 1=Half Duplex)
B58InternalInternal1.8V288SERIAL1_TERM (0=No Term, 1=120ohm Term)
G55InternalInternal1.8V490SERIAL2_MODE (0= RS232 or 1=RS485)
J51InternalInternal1.8V387SERIAL2_DUPLEX (0=Full Duplex, 1=Half Duplex)
K49InternalInternal1.8V389SERIAL2_TERM (0=No Term, 1=120ohm Term)

Using GPIO Pins Sourced Directly from the Xavier/TX2/TX1

To use a GPIO pin that is sourced directly from the Jetson first it will need to be “exported”.  This tells the Tegra’s GPIO driver that the pin is to be used as a GPIO. The example below demonstrates how to export pin 186 to be used as a GPIO:

echo 186 > /sys/class/gpio/export

The GPIO Reference Table maps out which pin on your carrier maps to which sysfs pin number.  For this example we will continue using pin 186.

The pin can be set as either an input or an output. The following sets pin 186 to be an output:

echo  out > /sys/class/gpio/gpio186/direction

While this would set pin 186 to be an input (default):

echo  in > /sys/class/gpio/gpio186/direction

Another option is changing if the pin is an “active high” (reads 1 when the pin is held high), or “active low” (reads 1 when the pin is held low). This is modified by writing a 0 or 1 to “active_low” this would set pin 186 to be active low:

echo  1 > /sys/class/gpio/gpio186/active_low

Now that the pin is setup, you can read or write to it using the “value” file.

This reads the current value of the pin, returning 1 or 0.

cat /sys/class/gpio/gpio186/value

While this writes a 1 to the pin (if the pin is configured to be an output)

echo 1 > /sys/class/gpio/gpio186/value

If you would like to monitor an input pin in the terminal to see if it is being toggled you can use this command.  It continuously reads the value of the pin every 0.1 seconds and shows it in the terminal.  It can be exited by using ctrl-c.

while [ True ] ; do echo -ne $(cat /sys/class/gpio/gpio186/value) "\r"; sleep 0.1;  done

Using GPIO Pins Sourced from I2C Expanders

Some of Connect Tech’s carriers use I2C GPIO expanders for their external GPIO pins.  These are interfaced with by using the I2C utilities in Linux to read and write from the I2C IC.  The table below gives a breakdown of which expanders are on each board, what I2C address they are set to and which I2C bus they are on.

Part NumberBoard NameExpander Part#I2C addressI2C Bus Number
ESG503, ASG005RudiTI TCA95390x74L4T24.2.1 - /dev/i2c0
L4T28.1 - /dev/i2c1
ASG006SpacelyTI TCA95390x77L4T24.2.1 - /dev/i2c1
L4T28.1 - /dev/i2c0
ASG007CogswellExar XRA12000x20L4T24.2.1 - /dev/i2c0
L4T28.1 - /dev/i2c1

Configuration using I2C

These are some brief descriptions of important registers that can be read and written to on the I2C expanders, more details can be found in the datasheets linked in the table:

0x00 = Input 0 – 7  Status Register (Not all inputs/outputs are implemented on all carriers see the GPIO Reference Table)

0x01 = Input  8 – 15 Status Register (Not all inputs/outputs are implemented on all carriers see the GPIO Reference Table)

0x02 = Output 0-7 Register – Default = 0xFF, 0 = GND, 1 = 3.3V HIGH (only valid if I/O set to an output in register 0x06)

0x03 = Output 8-15 Register – Default = 0xFF, 0 = GND, 1 = 3.3V HIGH (only valid if I/O set to an output in register 0x06)

0x06 = I/O Mode 0-7 set register – Default = 0xFF (all inputs), (0 = output, 1 = input)

0x07 = I/O Mode 8-15 set register – Default = 0xFF (all inputs), (0 = output, 1 = input)

To read a register from the I2C Expander you can use:

i2cget -y (BUS) (ADDR) (REGISTER)

To write to a register use:

i2cset –y (BUS) (ADDR) (REGISTER) (DATA)

Here is an example of how to set pin I/O-5  on the Rudi as an input:

i2cset –y 0x0 0x06 0x74 0x01 #P00 as input

To read the value of the inputs on the Rudi:

i2cget -y 0x0 0x74 0x00 #least significant bit of the return value is value of I/O-5(P00)

If you wish to access the GPIO devices via the I2C when the driver is holding the address (i2cdetect returns UU on address), you may add the -f flag to either the i2cget and ic2set commands.

Configuration using GPIO using I2C Driver

When the Connect Tech Board Support Package is installed using TX2/TX1, (see release notes for details). The GPIO are accessible through the system driver. This can be assessed by applying the driver to the I2C BUS of the Expansion IC (See above Table for I2C BUS).

Check the following command to see if the Driver is already applied you will see a UU under the address location:

i2cdetect (BUS)

If the bus is not held by the driver than you will see the address number under the location such as 74 for the RUDI. You may set the driver with the following command:

echo (NOTE 1) (ADDR) > /sys/bus/i2c/devices/(BUS)/new_device

When the BUS is taken by the driver the corresponding address of the I2C Expander will be occupied by a UU. You may also see the GPIO ports assigned to the expander by issuing the following command:

cat /sys/kernel/debug/gpio

To use the GPIO on the expander you must release the GPIO port from the driver using the following command:

echo (SYSFS) > /sys/class/gpio/export

When in this directory, you may use the echo commands as done previously Using GPIO Pins Sourced Directly from the Xavier/TX2/TX1 section.

Notes

[1] For the Rudi and Spacely carriers use “tca9539”, for the Cogswell use “xra1200”

Go to Top