Unable to get GPIO value

Hello, I’m using a custom development board based on verdin for IMX8MP with TorizonCore 6.4.0. In my device tree, I configured MX8MP_IOMUXC_SD2_DATA1__GPIO2_IO16 GPIO to 0x1C4 and disabled the SD device usdhc2. I can set the GPIO high or low but I cannot read the value back. The goal here is to power ON/OFF an external device (LTE module):
lte_command_schematic

Commands:

# After booting
gpioget 1 16         # returns 0 but the GPIO is pulled up and the level is actually high
gpioset 1 16=0       # works (effectively sets the level low)
gpioget 1 16         # returns 0 (ok)
gpioset 1 16=1       # works (effectively sets the level high)
gpioget 1 16         # returns 0 when I expected 1

There is a strange behaviour because when the GPIO is 0, calling gpioget 1 16 is setting the GPIO to 1.4V. I wonder if this is related to IO voltage of the SD card as it can be changed with MX8MP_IOMUXC_GPIO1_IO04__USDHC2_VSELECT.

The problem may be linked to this subject.
Please find my device tree overlay here:
imx8mp-transmission-system-clean.dts (4.4 KB)

Thanks

Clément

gpioget/set utilities lack controls to specify pin input/output direction. So the only way to control pin direction is to always set direction to output with gpioset and always set direction to input with gpioget.

You may verify it with gpio sysfs if you have it enabled in kernel. Something like echo 48 > /sys/class/gpio/export isn’t changing (gpio 32*1+12=48) pin direction. You may for example sysfs export your pin; set its /sys/class/gpio/gpioN/direction to “out”; unexport pin; and export it again to see direction doesn’t change… unless you call gpioget between unexport and export.

It would be nice to see gpioset perhaps unchanged, but gpioget should have command line switch to specify you don’t want to change pin direction.

2 Likes

Got it ! Gpioget is setting the pin as input before reading the value but that’s not what I wanted…

I’m using sysfs with these scripts and its working !

gpio-set.sh (640 Bytes)
gpio-get.sh (618 Bytes)

Many thanks

Clément

1 Like