Open main menu

DAVE Developer's Wiki β

DESK-MX9-L/Peripherals/GPIOs

< DESK-MX9-L
History
Issue Date Notes
2024/02/02 DESK-MX9-L-5.0.0 release



Contents

Peripheral GPIOsEdit

i.MX93 can handle external pins in many different ways and most of them can be configured as GPIOs. When a pin is set as a GPIO, it is possible to read its value, change its direction or change output value directly from the shell.

Device tree configurationEdit

Here below is an example of device tree configuration for using the GPIOs and enabling UART2 on standard DAVE's kit for the AURA SOM:

From imx93-aura-cb2001.dts:

	leds {
		compatible = "gpio-leds";
		status = "okay";

		uart2_en {
			label = "uart2_en";
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_uart2_en>;
			gpios = <&gpio2 4 GPIO_ACTIVE_HIGH>;
			default-state = "on";
		};

		uart2_mode {
			label = "uart2_mode";
			pinctrl-names = "default";
			pinctrl-0 = <&pinctrl_uart2_mode>;
			gpios = <&gpio3 27 GPIO_ACTIVE_HIGH>;
			default-state = "off";
			status = "disabled";
		};
	};
};

while the related pad configuration has been defined in the iomuxc section:

	pinctrl_uart2_mode: uart2_mode {
		fsl,pins = <
			MX93_PAD_CCM_CLKO2__GPIO3_IO27			0x31e
		>;
	};

Accessing the peripheralEdit

Linux messages at boot timeEdit

With the previous leds configuration for the GPIOs, it is possible to find them on sysfs under /sys/class/leds sub-directory:

root@desk-mx93:~# ls -la /sys/class/leds/uart2*
total 0
lrwxrwxrwx  1 root root 0 Mar  3  2023 uart2_en -> ../../devices/platform/leds/leds/uart2_en
root@desk-mx93:~#

Usage with libgpiodEdit

Information about GPIOs library libgpiod - C library and tools - can be found on git.kernel.org

It is possible to compile libgpiod in the target (if the related Yocto package is not available for installation). Once the autoconf-archive package has been installed

dnf install autoconf-archive

it is possible to clone the libgpiod git repository and compile the related sources:

git clone https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
cd libgpiod 
./autogen.sh --enable-tools=yes --prefix=/usr/local 
make
make install

Once installed, the gpio utilities are available in the target:

root@desk-mx93:~# gpio
gpiodetect  gpioget     gpioinfo    gpiomon     gpionotify  gpioset
gpiomon exampleEdit

If a push button, with proper pull-up, is connected to a GPIO line available - for example using the J33.28 pin available on SBC AXEL Lite WIDE connector - the related GPIO can be used as an interrupt:

  • J33.28 is connected to J10.191 SO-DIMM pin
    • J33 connector is the WIDE connector in the AURA Evaluation Kit
    • J10 connector is the SO-DIMM connector in the AURA Evaluation Kit
    • ALT-0 alternate function for this pin is GPIO2_IO12
  • the corresponding pin number is associated to gpiochip0 line 12
  • gpiomon utility can be used for monitor the pin status and triggering, for example, the falling-edge event:
root@desk-mx93:~# gpiomon -e falling -c 0 12
503.836012614   falling gpiochip0 12
504.229875114   falling gpiochip0 12
504.229962281   falling gpiochip0 12
504.229970823   falling gpiochip0 12
^Croot@desk-mx93:~#
gpioset exampleEdit

For changing a GPIO output status, the gpioset utility can be used:

  • the following example set to High the pin GPIO_IO00 connected to J10.179 SO-DIMM pin
root@desk-mx93:~# gpioset -c 0 0=1