2021-01-15 04:40 AM
Hello,
I'd like use several gpio buttons to onboard CN2 connector (STM gpios PF0, PF1, PF3, PF4, PF6, PF8). So I've add following string to stm32mp157c-dk2.dts file
buttonkeys {
compatible = "gpio-keys";
left-key {
label="Left key";
gpios=<&gpiof 0 GPIO_ACTIVE_LOW>;
linux,code=<105>;
};
evtest gives me multiple events (press/release) when key not pressed. So what is cause of this and how to correct add gpio processing?
Thanks,
Alex
Solved! Go to Solution.
2021-01-29 10:50 AM
Hello Alex,
Looking through the gpio_keys.c driver , a cleaner solution would be to use the "debounce-interval" subnode property which defaults to 5ms.
https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt
Regards,
Olivier
2021-01-15 07:48 AM
Hello Alex Mach (Community Member),
You may add a pullup/pulldown to prevent multiple events to occur while key is not pressed. You can combine GPIO_ACTIVE_LOW and GPIO_PULL_UP in the DT.
gpios=<&gpiof 0 (GPIO_ACTIVE_LOW |GPIO_PULL_UP) >;
It already work for input lines and it has been recently added for ouput lines.
https://wiki.st.com/stm32mpu/wiki/How_to_control_a_GPIO_in_kernel_space
If it still doesn't work, If you are not using the most uptodate OpenSTLinux version (< V2.1.0) make sure you patch the gpiolib.c driver.
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index abdf448..da0d2e7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3128,6 +3128,13 @@
}
set_output_value:
+ if (test_bit(FLAG_PULL_UP, &desc->flags))
+ gpio_set_config(gc, gpio_chip_hwgpio(desc),
+ PIN_CONFIG_BIAS_PULL_UP);
+ else if (test_bit(FLAG_PULL_DOWN, &desc->flags))
+ gpio_set_config(gc, gpio_chip_hwgpio(desc),
+ PIN_CONFIG_BIAS_PULL_DOWN);
+
return gpiod_direction_output_raw_commit(desc, value);
set_output_flag:
Regards,
Olivier
2021-01-18 05:17 AM
Hello Olivier!
Thank for your advice! Unfortunally combination GPIO_ACTIVE_LOW and GPIO_PULL_UP and path gpiolib.c driver help only for PF0 and PF8. Unpressed PF3, PF5, PF6 and PF9 still are cause to occure for multiple events. If I pullup these gpios using external resistor they work fine.
Thanks, Alex.
2021-01-18 06:51 AM
Hello Alex Mach (Community Member)
Strange to me if it works with PF0 and PF8 but not with the others. Are the ones still causing multiple events already used by some internal peripherals (FMC?)
Regards,
Olivier
2021-01-18 08:43 AM
If I pullup these gpios using external resistor they work fine. In case already used by some internal peripherals the ones shouldn't work at all, right?
Thanks,
Alex.
2021-01-18 11:23 AM
Or those pins are locked in use, or sensitivity to noise? Can you double check your configuration first?
root@stm32mp1:~# cat /sys/kernel/debug/pinctrl/soc\:pin-controller@50002000/pinconf-pins
Olivier
2021-01-21 01:29 AM
Hello Olivier!
root@stm32mp1:~# cat /sys/kernel/debug/pinctrl/soc\:pin-controller@50002000/pinconf-pins | grep PF
pin 80 (PF0): input - high - floating
pin 81 (PF1): analog
pin 82 (PF2): input - high - floating
pin 83 (PF3): input - high - floating
pin 84 (PF4): analog
pin 85 (PF5): input - high - floating
pin 86 (PF6): input - high - floating
pin 87 (PF7): analog
pin 88 (PF8): input - high - floating
pin 89 (PF9): input - high - floating
pin 90 (PF10): analog
pin 91 (PF11): alternate 10 (SAI2_SD_B) - push pull - floating - low speed
pin 92 (PF12): analog
pin 93 (PF13): analog
pin 94 (PF14): analog
pin 95 (PF15): alternate 5 (I2C1_SDA) - open drain - floating - low speed
I think those pins are sensitivity to noise. If I disconnect the button the events not occur.
Thanks,
Alex.
2021-01-29 10:50 AM
Hello Alex,
Looking through the gpio_keys.c driver , a cleaner solution would be to use the "debounce-interval" subnode property which defaults to 5ms.
https://www.kernel.org/doc/Documentation/devicetree/bindings/input/gpio-keys.txt
Regards,
Olivier