cancel
Showing results for 
Search instead for 
Did you mean: 

stm32mp157c-dk2 how to add gpio buttons to CN2 connector?

Alex Mach
Associate III

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

1 ACCEPTED SOLUTION

Accepted Solutions
OlivierK
ST Employee

​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

View solution in original post

7 REPLIES 7
OlivierK
ST Employee

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

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.

OlivierK
ST Employee

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

Alex Mach
Associate III

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.

OlivierK
ST Employee

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

Alex Mach
Associate III

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.

OlivierK
ST Employee

​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