drivers: gpio: stm32: support wkup pins configuration
Introduce a custom STM32_GPIO_WKUP GPIO flag. Use the newly introduced stm32_pwr_wkup_pin_cfg_gpio() public function to configure GPIO pins, that have the STM32_GPIO_WKUP flag in DT, as sources for STM32 PWR wake-up pins, on the condition that there is a wake-up pin that corresponds to each of them. These GPIO pins can then be used to power on the system after Poweroff like a reset pin. Signed-off-by: Abderrahmane Jarmouni <abderrahmane.jarmouni-ext@st.com>
This commit is contained in:
parent
559c72d7a6
commit
efc209b47f
2 changed files with 56 additions and 0 deletions
|
|
@ -22,11 +22,17 @@
|
|||
#include <zephyr/drivers/interrupt_controller/exti_stm32.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
#include <zephyr/drivers/misc/stm32_wkup_pins/stm32_wkup_pins.h>
|
||||
#include <zephyr/dt-bindings/gpio/stm32-gpio.h>
|
||||
|
||||
#include "stm32_hsem.h"
|
||||
#include "gpio_stm32.h"
|
||||
#include <zephyr/drivers/gpio/gpio_utils.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
LOG_MODULE_REGISTER(stm32, CONFIG_GPIO_LOG_LEVEL);
|
||||
|
||||
/**
|
||||
* @brief Common GPIO driver for STM32 MCUs.
|
||||
*/
|
||||
|
|
@ -541,6 +547,25 @@ static int gpio_stm32_config(const struct device *dev,
|
|||
|
||||
gpio_stm32_configure_raw(dev, pin, pincfg, 0);
|
||||
|
||||
#ifdef CONFIG_STM32_WKUP_PINS
|
||||
if (flags & STM32_GPIO_WKUP) {
|
||||
#ifdef CONFIG_POWEROFF
|
||||
struct gpio_dt_spec gpio_dt_cfg = {
|
||||
.port = dev,
|
||||
.pin = pin,
|
||||
.dt_flags = (gpio_dt_flags_t)flags,
|
||||
};
|
||||
|
||||
if (stm32_pwr_wkup_pin_cfg_gpio((const struct gpio_dt_spec *)&gpio_dt_cfg)) {
|
||||
LOG_ERR("Could not configure GPIO %s pin %d as a wake-up source",
|
||||
gpio_dt_cfg.port->name, gpio_dt_cfg.pin);
|
||||
}
|
||||
#else
|
||||
LOG_DBG("STM32_GPIO_WKUP flag has no effect when CONFIG_POWEROFF=n");
|
||||
#endif /* CONFIG_POWEROFF */
|
||||
}
|
||||
#endif /* CONFIG_STM32_WKUP_PINS */
|
||||
|
||||
/* Release clock only if pin is disconnected */
|
||||
if (((flags & GPIO_OUTPUT) == 0) && ((flags & GPIO_INPUT) == 0)) {
|
||||
err = pm_device_runtime_put(dev);
|
||||
|
|
|
|||
31
include/zephyr/dt-bindings/gpio/stm32-gpio.h
Normal file
31
include/zephyr/dt-bindings/gpio/stm32-gpio.h
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2024 STMicroelectronics
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_STM32_GPIO_H_
|
||||
#define ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_STM32_GPIO_H_
|
||||
|
||||
/**
|
||||
* @brief STM32 GPIO specific flags
|
||||
*
|
||||
* The driver flags are encoded in the 8 upper bits of @ref gpio_dt_flags_t as
|
||||
* follows:
|
||||
*
|
||||
* - Bit 8: Configure a GPIO pin to power on the system after Poweroff.
|
||||
*
|
||||
* @ingroup gpio_interface
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Configures a GPIO pin to power on the system after Poweroff.
|
||||
* This flag is reserved to GPIO pins that are associated with wake-up pins
|
||||
* in STM32 PWR devicetree node, through the property "wkup-gpios".
|
||||
*/
|
||||
#define STM32_GPIO_WKUP (1 << 8)
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_STM32_GPIO_H_ */
|
||||
Loading…
Reference in a new issue