GPIO handling at i.MX8M Mini
GPIO-Architectur i.MX8M Mini
02 17, 2026 09:30
The phyBOARD-Polis has a set of pins especially dedicated to user Input / Outputs. Those pins are connected directly to i.MX 8M Mini pins and are muxed as GPIOs (General-Purpose Input / Output). They are directly usable in Linux userspace.
The processor has five GPIO ports (gpio1 to gpio5), with each port controlling 32 pins. In addition, there are GPIOs of the MCA (Microcontroller Companion) and external controllers.
For more information about the i.MX8M Mini/Nano visit phycore-imx-8m-mini/nano or contact support@phytec.de.
Possible uses
| Usecase | Example | ||
|---|---|---|---|
| Industrial automation and control | Machine control | Signal monitoring | Process automation |
| IoT and Smart devices | IoT sensor integration | Actuator control | Edge computing |
| Medical applications | Medical devices | Signal processing | Human-Machine Interface |
| Mulitmedia and user interfaces (HMI) | Display control | Audio applications | Control panels |
| Transportation and agriculture | Vehicle control | Agricultural equipment | |
| Embedded systems and prototyping | Real-time control | Prototyping | |
| Communication systems | Signal routing | Error detection and status indicators | |
The GPIO functionality of the i.MX8M Mini is a key component for versatile applications in industrial, IoT, medical, multimedia and embedded systems. Thanks to the flexible configuration via the device tree and the support of numerous protocols such as CAN bus, SPI and I2C, the GPIO pins provide a powerful interface for control and signal processing in modern system designs.
Voltage range of GPIOs
The GPIOs operate at 1.8 V or 3.3 V, depending on the power domain of the pad. The voltage can be determined using the schematics and the hardware reference manual (Downloadable from manufacturer NXP).
GPIO integration
The choice of GPIO integration on the i.MX8M Mini depends heavily on the specific application and the desired functions. Here is an overview of when which GPIO integration makes sense:
- Direct GPIO control via kernel
- Real-time applications: When precise control of GPIO pins is required
- Programming close to the hardware: If GPIOS are to be controlled directly in the kernel or by user-defined drivers
- Individual pin configuration: For applications in which the GPIO pins require specific electrical properties
- Examples:
- Controlling LEDs or relays
- Reading switches or sensors with high frequency
- Configuration of interrupt-controlled GPIOs (e.g. for events such as button presses)
- Examples:
- Sysfs interface
- Simplicity: Simple GPIO control without kernel programming
- Prototyping: When GPIOs need to be tested quickly
- Non-time-critical applications: For tasks where latency is not an issue
- Examples:
- Activating/deactivating peripheral devices
- Reading status of a button or switch
- Control of user LED
- Examples:
- Internal i.MX 8M Mini GPIO banks sysfs representation:
- gpiochip0, gpiochip32, gpiochip64, gpiochip96, and gpiochip128
- Integration into devicetree (GPIO-Hog group)
- Complex systems: GPIOs are part of a larger system and need to interact with other peripheral devices
- Automated configuration: If GPIOs are to be configured automatically at system startup
- Multiplexing required: When pins have multiple functions (e.g. UART, I2C) and need to be used as GPIOs
- Examples:
- Powermanagement (Regulator)
- Use of a pin for interrupt signals
- Activation of firmware update via GPIO pin
- Reset lines for controllers or transceivers
- Examples:
- Use of high-level libraries or frameworks
- Abstraction level: For developers who do not want to deal with low-level configuration
- Rapid development: When time to market is critical
- Examples:
- Use of frameworks such as Zephyr OS to control GPIOs in embedded systems
- Integration in IoT-applications
- Examples:
- Interrupt-based GPIO usage
- Event-controlled applications: If a signal change vent is to be detected
- Examples:
- Interrupt handling (e.g. button press)
- Event-controlled data processing
- Examples:
- Event-controlled applications: If a signal change vent is to be detected
GPIOs at Devicetree
Configure GPIO pins at dts over IOMUX to settle his function.
gpio1: gpio1 {
gpio-controller;
#gpio-cells = <2>;
};
[...]
data-gpios = <&gpio1 12 0>,
<&gpio1 13 0>,
<&gpio1 14 0>,
<&gpio1 15 0>;Official kernel.org GPIO Documentation
Userspace GPIO handling
If the GPIO is to be toggled from userspace, there are two options. You can work with the outdated sysfsor the new GPIO chardev API.
sysfs
The obsolete sysfs interface should no longer be used. Deprecated means that it will disappear from the kernel in the future.
Support to access GPIOs via sysfs is not enabled by default any more. It is only possible with manually enabling CONFIG_GPIO_SYSFS in the kernel configuration. To make CONFIG_GPIO_SYSFS visible in menuconfig the option CONFIG_EXPERT has to be enabled first.
You can also add this option for example to the defconfig you use in arch/arm64/configs/ in the linux kernel sources. For our NXP based releases, this could be for example imx8_phytec_distro.config:
… CONFIG_EXPERT=y CONFIG_GPIO_SYSFS=y …
Gpiolib
gpiolib is a framework inside the kernel to manage the GPIO allocation. The chardev interface replaces the deprecated sysfs interface and comes along with a new API to access GPIO lines from userspace.
To use gpiolib, activate CONFIG_GPIOLIB at kernel configuration if not already enabled.
… CONFIG_GPIOLIB=y …
You can also add this option for example to the defconfig you use in arch/arm64/configs/ in the linux kernel sources.
Interface
target~$: ls /dev/gpiochip* /dev/gpiochip0 /dev/gpiochip2 /dev/gpiochip4 /dev/gpiochip1 /dev/gpiochip3
The new char device API prevents manipulating GPIO with echo and cat, but it delivers new file operations like:
open(), read(), write(), ioctl(), poll(), close()
To easily access with this new interface, use the library libgpiod.
Kernel declaration
Libgpiod
Modern systems use the libgpiod library and associated utilities to access GPIOs from userspace.
More information about downloading, building and installing libgpiod can be found here: libgpiod.
Git: libgpiod.git
Command-line tool provided by libgpiod
Detecting the gpio chips:
target:~$ gpiodetect gpiochip0 [30200000.gpio] (32 lines) gpiochip1 [30210000.gpio] (32 lines) gpiochip2 [30220000.gpio] (32 lines) gpiochip3 [30230000.gpio] (32 lines) gpiochip4 [30240000.gpio] (32 lines)
Get detailed information about gpiochips (name, consumer, direction, active state and additional flags)
target:~$ gpioinfo gpiochip0
Read and write GPIO:
target:~$ gpioget gpiochip0 20 target:~$ gpioset --mode=exit gpiochip0 20=0
Some of the user IOs are used for special functions. Before using a user IO, refer to the schematic or the hardware manual of your board to ensure that it is not already in use.
GPIO at driver level
The libgpiod project provides several functions to use in drivers or C programs. You can even use it at C++ and Python.
Hog group
This is a mechanism for automatic GPIO request and configuration during driver initialization. It is the right choise if you want to set fix direction, set a specific state at initialisation or permanently reserve the gpio at the devicetree.
To create a GPIO hog group on an embedded system with a Linux kernel operating system, follow these steps:
- Device Tree Configuration:
- Define the GPIO hog group as a child node of the GPIO controller in the device tree.
Example
Activate CONFIG_GPIOLIB at kernel configuration as mentioned above.
&gpio5 {
gpio-hog;
gpio-hog-group {
gpios = <&gpio5 1 GPIO_ACTIVE_HIGH>;
output-high;
line-name = "my-gpio-hog";
};
};If used like this, the GPIO pin 1 of gpio5 will be set at system start to high and will be blocked for other drivers.
Important properties
gpio-hog: Identifies the node as a GPIO hog gpios: Specifies the GPIOs to be configured output-high/output-low/input: Specifies the direction and the initial state line-name: Optional name for the GPIO line
/etc/rc.local
You can add GPIO initialization at /etc/rc.local.
pigs modes 12 w pigs w 12 1
This line configures GPIO 12 to output and "high".
Bash script
#!/bin/bash pigs modes 17 w pigs w 17 1 exit 0
Driver implementation
If you want to create the GPIO hogs programmed, you can do this in your driver code:
struct gpiod_hog gpio_hog_table[] = {
GPIO_HOG("gpio.0", 10, "foo", GPIO_ACTIVE_LOW, GPIOD_OUT_HIGH), { } };
gpiod_add_hogs(gpio_hog_table);
This method adds the GPIO hogs as soon as the GPIO chip is created or - if the chip already exists - when the hog table is registered. After compiling and flashing, the GPIO-Hog group is now automatically configured at system startup without the need for additional userspace code. This is particularly useful for initializing GPIOs that are required for basic system functions.
Compare hog vs non-hog
| aspect | hog group | non-hog group |
|---|---|---|
| Reservation | permanent (till reboot) | temporary (released after init) |
| dts property | gpio-hog | gpio-initval |
| kernel API | gpiod_hog() | gpiod_initialize() |
| use case | critical hardware | preallocation for later use |
The choice which integration suits best depends on the requirements in term of latency, complexity and flexibility.
- Sysfs: Is suitable for simple tasks and prototyping, but it should not be used for new projects.
- device tree: Is ideal for complex systems and automated configuration. (Hog or non-hog)
- Direct kernel control: Real-time applications benefit from direct kernel control or interrupt-based approaches.
Conclusion
GPIOs (General Purpose Input/Output) are universal interfaces that can be configured as inputs or outputs. They are particularly flexible as they have no specific purpose and can be controlled by software.
GPIOs are essential for the interaction of embedded systems with their environment and offer developers a cost-effective and flexible solution for a wide range of tasks.