Verify that the user LED 1 and TAMPER KEY interfaces are functional via the standard gpio-leds and gpio-keys interfaces:
- Use the following command to turn on the user LED: 1 (LD1):
# echo 1 > /sys/class/leds/user-led-1/brightness
- Use the following command to turn off the USER LED 1:
# echo 0 > /sys/class/leds/user-led-1/brightness
- From the Linux shell, start the evtest utility. Then press the TAMPER KEY button and make sure the evtest has reported the events correctly:
/ # evtest /dev/input/event0
Event: time 141.204234, type EV_KEY, code KEY_A, value 1
Event: time 141.204234, type EV_SYN, code SYN_REPORT, value 0
Event: time 144.897518, type EV_KEY, code KEY_A, value 0
Event: time 144.897518, type EV_SYN, code SYN_REPORT, value 0
Linux Raw GPIO Interface
In order to test raw GPIO functions, disable definition of the TAMPER KEY button in the kernel DTS file, then rebuild and reinstall the project:
diff --git a/rootfs/rootfs.dts.STM32H753IEVAL b/rootfs/rootfs.dts.
STM32H753IEVAL
index 84cdcb43..41f64f18 100644
--- a/rootfs/rootfs.dts.STM32H753IEVAL
+++ b/rootfs/rootfs.dts.STM32H753IEVAL
@@ -74,11 +74,13 @@
gpio-keys {
compatible = "gpio-keys";
+#if 0
button-tamper {
label = "button-tamper";
linux,code = <KEY_A>;
gpios =<&gpioc 13 GPIO_ACTIVE_LOW>;
};
+#endif
};
};
Proceed with the testing:
- Export PC13 and configure it as an input:
/ # echo 45 > /sys/class/gpio/export
/ # echo in > /sys/class/gpio/PC13/direction
- Make sure the value of PC13 is 1 when the TAMPER KEY button is untouched (due to the internal PULL-UP being enabled):
/ # cat /sys/class/gpio/PC13/value
1
/ #
- Press and hold the TAMPER KEY button and make sure the PC13 value has changed to 0:
/ # cat /sys/class/gpio/PC13/value
0
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 useful if you decide to try an alternative approach.
The following article describes accessing GPIOs from the kernel context:
https://lwn.net/Articles/532714/
To work with GPIOs from the user space, there are the following possibilities:
- Using the GPIOLIB interface (described in this application note):
https://www.kernel.org/doc/Documentation/gpio/sysfs.txt
- Using the drivers of the Linux LED/Input subsystems:
https://www.kernel.org/doc/Documentation/leds/leds-class.txt
https://www.kernel.org/doc/Documentation/input/input.txt
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.