@@ -2224,13 +2224,13 @@ static int uart_stm32_registers_configure(const struct device *dev)
22242224 /* Wait until TEACK flag is set */
22252225 while (!(LL_USART_IsActiveFlag_TEACK (usart ))) {
22262226 }
2227- #endif /* ! USART_ISR_TEACK */
2227+ #endif /* USART_ISR_TEACK */
22282228
22292229#ifdef USART_ISR_REACK
22302230 /* Wait until REACK flag is set */
22312231 while (!(LL_USART_IsActiveFlag_REACK (usart ))) {
22322232 }
2233- #endif /* ! USART_ISR_REACK */
2233+ #endif /* USART_ISR_REACK */
22342234
22352235 return 0 ;
22362236}
@@ -2301,14 +2301,12 @@ static void uart_stm32_suspend_setup(const struct device *dev)
23012301 LL_USART_ClearFlag_ORE (usart );
23022302}
23032303
2304- static int uart_stm32_pm_action (const struct device * dev ,
2305- enum pm_device_action action )
2304+ static int uart_stm32_pm_action (const struct device * dev , enum pm_device_action action )
23062305{
23072306 const struct uart_stm32_config * config = dev -> config ;
23082307 struct uart_stm32_data * data = dev -> data ;
23092308 int err ;
23102309
2311-
23122310 switch (action ) {
23132311 case PM_DEVICE_ACTION_RESUME :
23142312 /* Set pins to active state */
@@ -2317,21 +2315,34 @@ static int uart_stm32_pm_action(const struct device *dev,
23172315 return err ;
23182316 }
23192317
2320- /* Enable clock */
2321- err = clock_control_on (data -> clock ,
2322- (clock_control_subsys_t )& config -> pclken [0 ]);
2318+ /* Enable bus clock */
2319+ err = clock_control_on (data -> clock , (clock_control_subsys_t )& config -> pclken [0 ]);
23232320 if (err < 0 ) {
23242321 LOG_ERR ("Could not enable (LP)UART clock" );
23252322 return err ;
23262323 }
23272324
2328- if ((IS_ENABLED (CONFIG_PM_S2RAM )) &&
2329- (!LL_USART_IsEnabled (config -> usart ))) {
2325+ if (!LL_USART_IsEnabled (config -> usart )) {
23302326 /* When exiting low power mode, check whether UART is enabled.
2331- * If not, it means we are exiting Suspend to RAM mode (STM32
2332- * Standby), and the driver needs to be reinitialized.
2327+ * If not, it means the peripheral has been powered down
2328+ * by the low-power mode. If suspend-to-RAM is enabled,
2329+ * assume the entire SoC has been powered down and do a
2330+ * full re-initialization. Otherwise, assume that the
2331+ * low-power mode shut down power to the UART but not
2332+ * critical peripherals (CPU, GPIO, RCC), which means
2333+ * we only have to reconfigure this UART instance.
2334+ *
2335+ * STOP2 on STM32WLE5 is an example of such low-power mode.
23332336 */
2334- uart_stm32_init (dev );
2337+ if (IS_ENABLED (CONFIG_PM_S2RAM )) {
2338+ err = uart_stm32_init (dev );
2339+ } else {
2340+ err = uart_stm32_registers_configure (dev );
2341+ }
2342+
2343+ if (err < 0 ) {
2344+ return err ;
2345+ }
23352346 }
23362347 break ;
23372348 case PM_DEVICE_ACTION_SUSPEND :
0 commit comments