samples: boards: stm32: no need to configure button pin

The gpio pin that will be used as a source for PWR wake-up pins does not
actually need to be configured as input, hence input_gpio_keys driver does
not need to be involved. As far as GPIO controller is concerned, the pin
can be in analog state.

Also, it's clearer & safer to call gpio_pin_configure_dt directly in the
application with the STM32_GPIO_WKUP flag, just before calling Poweroff,
instead of relying on a driver, like input_gpio_keys to do it just after
boot behind the scenes, & risk not having the correct wake-up pins config
when Poweroff is finally called.

Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
This commit is contained in:
Abderrahmane Jarmouni 2024-06-11 00:08:38 +02:00 committed by Alberto Escolar
parent 5722576186
commit ed95cd9ab3
6 changed files with 4 additions and 32 deletions

View File

@ -4,18 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/gpio/stm32-gpio.h>
/ {
aliases {
wkup-src = &user_button;
};
};
&user_button {
gpios = <&gpioc 13 (GPIO_ACTIVE_HIGH | STM32_GPIO_WKUP)>;
};
&pwr {
status = "okay";
};

View File

@ -4,18 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/gpio/stm32-gpio.h>
/ {
aliases {
wkup-src = &user_button;
};
};
&user_button {
gpios = <&gpioc 13 (GPIO_ACTIVE_HIGH | STM32_GPIO_WKUP)>;
};
&pwr {
status = "okay";
};

View File

@ -4,18 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/gpio/stm32-gpio.h>
/ {
aliases {
wkup-src = &user_button;
};
};
&user_button {
gpios = <&gpioc 13 (GPIO_ACTIVE_HIGH | STM32_GPIO_WKUP)>;
};
&pwr {
status = "okay";
};

View File

@ -4,18 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/dt-bindings/gpio/stm32-gpio.h>
/ {
aliases {
wkup-src = &user_button_1;
};
};
&user_button_1 {
gpios = <&gpioa 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP | STM32_GPIO_WKUP)>;
};
&pwr {
status = "okay";
};

View File

@ -1,7 +1,2 @@
CONFIG_POWEROFF=y
CONFIG_STM32_WKUP_PINS=y
CONFIG_INPUT=y
CONFIG_INPUT_GPIO_KEYS=y
CONFIG_PM=n
CONFIG_PM_DEVICE=n
CONFIG_PM_DEVICE_RUNTIME=n

View File

@ -10,6 +10,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/poweroff.h>
#include <zephyr/dt-bindings/gpio/stm32-gpio.h>
#define WAIT_TIME_US 4000000
@ -24,14 +25,14 @@ static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
int main(void)
{
__ASSERT_NO_MSG(gpio_is_ready_dt(&button));
printk("\nWake-up button set up at %s pin %d\n", button.port->name, button.pin);
printk("\nWake-up button is connected to %s pin %d\n", button.port->name, button.pin);
__ASSERT_NO_MSG(gpio_is_ready_dt(&led));
gpio_pin_configure_dt(&led, GPIO_OUTPUT_ACTIVE);
gpio_pin_set(led.port, led.pin, 1);
printk("Device is ready\n");
/* Setup button GPIO pin as a source for exiting Poweroff */
gpio_pin_configure_dt(&button, STM32_GPIO_WKUP);
printk("Will wait %ds before powering the system off\n", (WAIT_TIME_US / 1000000));
k_busy_wait(WAIT_TIME_US);