Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions drivers/gpio/gpio_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ static int gpio_stm32_config(const struct device *dev,
{
int err;
uint32_t pincfg;
struct gpio_stm32_data *data = dev->data;

/* figure out if we can map the requested GPIO
* configuration
Expand All @@ -479,11 +480,13 @@ static int gpio_stm32_config(const struct device *dev,
}

/* Enable device clock before configuration (requires bank writes) */
if (((flags & GPIO_OUTPUT) != 0) || ((flags & GPIO_INPUT) != 0)) {
if ((((flags & GPIO_OUTPUT) != 0) || ((flags & GPIO_INPUT) != 0)) &&
!(data->pin_has_clock_enabled & BIT(pin))) {
err = pm_device_runtime_get(dev);
if (err < 0) {
return err;
}
data->pin_has_clock_enabled |= BIT(pin);
}

if ((flags & GPIO_OUTPUT) != 0) {
Expand Down Expand Up @@ -515,12 +518,14 @@ static int gpio_stm32_config(const struct device *dev,
}
#endif /* CONFIG_STM32_WKUP_PINS */

/* Release clock only if pin is disconnected */
if (((flags & GPIO_OUTPUT) == 0) && ((flags & GPIO_INPUT) == 0)) {
/* Decrement GPIO usage count only if pin is now disconnected after being connected */
if (((flags & GPIO_OUTPUT) == 0) && ((flags & GPIO_INPUT) == 0) &&
(data->pin_has_clock_enabled & BIT(pin))) {
err = pm_device_runtime_put(dev);
if (err < 0) {
return err;
}
data->pin_has_clock_enabled &= ~BIT(pin);
}

return 0;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpio/gpio_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ struct gpio_stm32_data {
const struct device *dev;
/* user ISR cb */
sys_slist_t cb;
/* keep track of pins that are connected and need GPIO clock to be enabled */
uint32_t pin_has_clock_enabled;
};

/**
Expand Down