Skip to content

Commit e4a8b27

Browse files
HoZHelcfriedt
authored andcommitted
drivers: serial: Enable UART wake-up line in STM32
Enable UART wake-up line in STM32 driver. Signed-off-by: Ali Hozhabri <[email protected]>
1 parent 85318a9 commit e4a8b27

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

drivers/serial/uart_stm32.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
#include <stm32_ll_usart.h>
3939
#include <stm32_ll_lpuart.h>
4040
#if defined(CONFIG_PM) && defined(IS_UART_WAKEUP_FROMSTOP_INSTANCE)
41-
#include <stm32_ll_exti.h>
41+
#include <stm32_ll_pwr.h>
42+
#include <zephyr/drivers/interrupt_controller/intc_exti_stm32.h>
4243
#endif /* CONFIG_PM */
4344

4445
#include <zephyr/linker/linker-defs.h>
@@ -121,6 +122,27 @@ static void uart_stm32_pm_policy_state_lock_get_unconditional(void)
121122
}
122123
}
123124

125+
#if defined(CONFIG_PM) && defined(IS_UART_WAKEUP_FROMSTOP_INSTANCE)
126+
static void uart_stm32_pm_enable_wakeup_line(uint32_t wakeup_line)
127+
{
128+
#if defined(CONFIG_SOC_SERIES_STM32WB0X)
129+
ARG_UNUSED(wakeup_line);
130+
#if defined(PWR_CR3_EIWL2)
131+
/**
132+
* If SoC is equipped with LPUART instance,
133+
* enable the associated wake-up line in PWRC.
134+
*/
135+
LL_PWR_EnableInternWU2();
136+
#endif /* PWR_CR3_EIWL2 */
137+
#else
138+
if (wakeup_line != STM32_WAKEUP_LINE_NONE) {
139+
/* Enable EXTI line associated to UART wake-up event */
140+
stm32_exti_enable(wakeup_line, STM32_EXTI_TRIG_NONE, STM32_EXTI_MODE_IT);
141+
}
142+
#endif /* CONFIG_SOC_SERIES_STM32WB0X */
143+
}
144+
#endif /* CONFIG_PM && IS_UART_WAKEUP_FROMSTOP_INSTANCE */
145+
124146
static void uart_stm32_pm_policy_state_lock_get(const struct device *dev)
125147
{
126148
struct uart_stm32_data *data = dev->data;
@@ -2277,21 +2299,24 @@ static int uart_stm32_registers_configure(const struct device *dev)
22772299
LL_USART_SetWKUPType(usart, LL_USART_WAKEUP_ON_RXNE);
22782300
LL_USART_EnableIT_WKUP(usart);
22792301
LL_USART_ClearFlag_WKUP(usart);
2280-
#endif
2302+
#endif /* USART_CR3_WUFIE */
2303+
2304+
#if !defined(CONFIG_SOC_SERIES_STM32WB0X) || defined(USART_CR1_UESM)
22812305
LL_USART_EnableInStopMode(usart);
2306+
#endif /* !CONFIG_SOC_SERIES_STM32WB0X || USART_CR1_UESM */
22822307

2283-
if (config->wakeup_line != STM32_WAKEUP_LINE_NONE) {
2284-
/* Prepare the WAKEUP with the expected EXTI line */
2285-
LL_EXTI_EnableIT_0_31(BIT(config->wakeup_line));
2286-
}
2308+
/* Enable the wake-up line signal (if applicable to hardware) */
2309+
uart_stm32_pm_enable_wakeup_line(config->wakeup_line);
22872310
}
2311+
22882312
#if defined(CONFIG_SOC_SERIES_STM32U5X) && DT_HAS_COMPAT_STATUS_OKAY(st_stm32_lpuart)
22892313
if (config->wakeup_source) {
22902314
/* Allow LPUART to operate in STOP modes. */
22912315
LL_SRDAMR_GRP1_EnableAutonomousClock(LL_SRDAMR_GRP1_PERIPH_LPUART1AMEN);
22922316
}
2293-
#endif
2294-
#endif /* CONFIG_PM */
2317+
#endif /* CONFIG_SOC_SERIES_STM32U5X && DT_HAS_COMPAT_STATUS_OKAY(st_stm32_lpuart) */
2318+
2319+
#endif /* CONFIG_PM && IS_UART_WAKEUP_FROMSTOP_INSTANCE */
22952320

22962321
LL_USART_Enable(usart);
22972322

0 commit comments

Comments
 (0)