Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This application note shows how to control STM32MP1 GPIOs in Linux.

1. Kernel sys Interface to GPIO is Deprecated

Starting with Linux kernel version 6.0, the /sys/class/gpio interface is removed from the kernel. The libgpiod3 library and utilities from the libgpiod-tools package should be used to configure and control processor's GPIOs from the user space.

2. Changes to the Kernel Configuration

No changes in the kernel configuration is required to control GPIOs from the user space in Linux.

...

Code Block
root@stm32mp15-som:~# gpioinfo
gpiochip0 - 16 lines:
        line   0:       "PA0"    input
        line   1:       "PA1"    input consumer="kernel"
        line   2:       "PA2"    input consumer="kernel"
…
        line  10:       "PD10"   output consumer="regulators:sub_nrst-regulator"
        line  11:       "PD11"   output consumer="regulators:eth_reg"
        line  12:       "PD12"   input
        line  13:       "PD13"   output consumer="panel-backlight"
        line  14:       "PD14"   output consumer="regulators:usb-host-regulator"
        line  15:       "PD15"   input
…
root@stm32mp15-som:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-15, parent: platform/soc:pinctrl@50002000, GPIOA:
 gpio-0   (PA0                 )
 gpio-1   (PA1                 )
 gpio-2   (PA2                 )
…
 gpio-58  (PD10                |regulators:sub_nrst-) out hi
 gpio-59  (PD11                |regulators:eth_reg  ) out hi
 gpio-60  (PD12                )
 gpio-61  (PD13                |panel-backlight     ) out hi
 gpio-62  (PD14                |regulators:usb-host-) out hi

3. Testing GPIO

For the User Push Button 1 the specific pin is MCO1 (PI11). The signal is pulled up when the button is not pressed and is driven low when the button is pressed. The gpioget command is used to print the state of a GPIO line. The command may be supplied with the active-low parameter if the requested signal is active low, as, for example, the line for the User Push Button 1. So, if the command is issued when the button is not pressed, the output should indicate that the line is not active:

...

Code Block
root@stm32mp15-som:~# gpioset -t 1000 PA13=1

Stop this test by pressing Ctrl-C.

4. Alternative Ways to Access GPIO

In Linux, you may access GPIOs using different approaches, not only the ones described in this application note above. Here are some external links that might be usefull if you decide to try an alternative approach.

...

These drivers allow to use different GPIO-related mechanisms already implemented in Linux. For example, you may simply force a LED connected to GPIO output to blink with the specified frequency, or simply force input subsystem to generate a some-button-pressed event on changing GPIO input.

5. Controlling GPIO from Kernel

The following article describes accessing GPIOs from the kernel context:
https://lwn.net/Articles/532714/

...