Skip to content

Commit 0792a85

Browse files
gautierg-stcarlescufi
authored andcommitted
drivers: serial: stm32: add reinit after standby
When resuming from low power mode, if UART is disabled, this means that we come from a mode that reset the registers, so we redo a full init of the driver. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent be26c71 commit 0792a85

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

drivers/serial/uart_stm32.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2081,17 +2081,26 @@ static int uart_stm32_pm_action(const struct device *dev,
20812081

20822082
switch (action) {
20832083
case PM_DEVICE_ACTION_RESUME:
2084-
/* Set pins to active state */
2085-
err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
2086-
if (err < 0) {
2087-
return err;
2088-
}
2084+
/* When exiting low power mode, check whether UART is enabled.
2085+
* If not, it means we are exiting Suspend to RAM mode (STM32
2086+
* Standby), and the driver need to be reinitialized
2087+
*/
2088+
if (LL_USART_IsEnabled(config->usart)) {
2089+
/* Set pins to active state */
2090+
err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT);
2091+
if (err < 0) {
2092+
return err;
2093+
}
20892094

2090-
/* enable clock */
2091-
err = clock_control_on(data->clock, (clock_control_subsys_t)&config->pclken[0]);
2092-
if (err != 0) {
2093-
LOG_ERR("Could not enable (LP)UART clock");
2094-
return err;
2095+
/* enable clock */
2096+
err = clock_control_on(data->clock,
2097+
(clock_control_subsys_t)&config->pclken[0]);
2098+
if (err != 0) {
2099+
LOG_ERR("Could not enable (LP)UART clock");
2100+
return err;
2101+
}
2102+
} else {
2103+
uart_stm32_init(dev);
20952104
}
20962105
break;
20972106
case PM_DEVICE_ACTION_SUSPEND:

0 commit comments

Comments
 (0)