Skip to main content
Associate II
December 12, 2024
Question

USART_ISR_WUF is not set after wake up from STOP2 by LPUART

  • December 12, 2024
  • 2 replies
  • 775 views

I've enabled STOP2 mode with the below code statement

 

void PWR_EnterStopMode(void)
{
/* USER CODE BEGIN PWR_EnterStopMode_1 */

 UART_WakeUpTypeDef WakeUpSelection;

 WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_STARTBIT;
 if (HAL_UARTEx_StopModeWakeUpSourceConfig(&hlpuart1, WakeUpSelection)!= HAL_OK)
 {
 Error_Handler();
 }

 __HAL_UART_ENABLE_IT(&hlpuart1, UART_IT_WUF);

 HAL_UARTEx_EnableStopMode(&hlpuart1);

/* USER CODE END PWR_EnterStopMode_1 */
 /**
 * When HAL_DBGMCU_EnableDBGStopMode() is called to keep the debugger active in Stop Mode,
 * the systick shall be disabled otherwise the cpu may crash when moving out from stop mode
 *
 * When in production, the HAL_DBGMCU_EnableDBGStopMode() is not called so that the device can reach best power consumption
 * However, the systick should be disabled anyway to avoid the case when it is about to expire at the same time the device enters
 * stop mode (this will abort the Stop Mode entry).
 */
 HAL_SuspendTick();

 /**
 * This function is called from CRITICAL SECTION
 */
 EnterLowPower();

 /************************************************************************************
 * ENTER STOP MODE
 ***********************************************************************************/
 LL_PWR_SetPowerMode(LL_PWR_MODE_STOP2);

 LL_LPM_EnableDeepSleep(); /**< Set SLEEPDEEP bit of Cortex System Control Register */

 /**
 * This option is used to ensure that store operations are completed
 */
#if defined (__CC_ARM)
 __force_stores();
#endif

 __WFI();

/* USER CODE BEGIN PWR_EnterStopMode_2 */

/* USER CODE END PWR_EnterStopMode_2 */
 return;
}

/**
 * @brief Exits Low Power Stop Mode
 * @note Enable the pll at 32MHz
 * none
 * @retval none
 */
void PWR_ExitStopMode(void)
{
/* USER CODE BEGIN PWR_ExitStopMode_1 */

/* USER CODE END PWR_ExitStopMode_1 */
 /**
 * This function is called from CRITICAL SECTION
 */
 ExitLowPower();

 HAL_ResumeTick();
/* USER CODE BEGIN PWR_ExitStopMode_2 */
 HAL_UARTEx_DisableStopMode(&hlpuart1);
/* USER CODE END PWR_ExitStopMode_2 */
 return;
}

 

LPUART could wake up MCU that I verifed by set a break point on 

 

void LPUART1_IRQHandler(void)

 

But USART_ISR_WUF is not set causing I can't handle RX message after resuming from STOP2 mode, is there anything I missed?

Charles_Li_0-1733991734504.png

 

2 replies

Roger SHIVELY
ST Employee
December 13, 2024

Hello @Charles_Li ,

 

This post has been escalated to the ST Online Support Team for additional assistance.  We'll contact you directly.

 

Regards,

Roger

Visitor II
December 20, 2024

Hello @Charles_Li @Roger SHIVELY 

I have exactly the same problem,

The frame is processed only when the MCU exits STOP2 mode.

I have the impression that the problem comes from the LPUART==>ISR==> IDLE bit which seems hardware and takes a while to go from 0 to 1.

Fabi1_0-1734708622064.png

 


I added a small delay right after the interrupt and everything works perfectly, but I don't think it's the best solution.

Very roughly, I tried a while loop

 

 

 

while (LL_LPUART_IsActiveFlag_IDLE(LPUART1) == 0)
{
}

 

 

 

This allowed me to understand that the problem was indeed coming from the LPUART==>ISR==> IDLE flag which was triggered a little after the IDLE interruption of my DMA.

@Roger SHIVELY  have you a solution?

 

Regards,

Fabien,

Associate II
December 23, 2024

I got expected flags after removing the below lines in PWR_ExitStopMode, 

 

		__HAL_UART_DISABLE_IT(huart,UART_IT_WUF);
		HAL_UARTEx_DisableStopMode(huart);

 

 

It goes to WakeupCallback when UART wakes MCU from STOP mode but not RxEventCallback

 /* UART wakeup from Stop mode interrupt occurred ---------------------------*/
 if (((isrflags & USART_ISR_WUF) != 0U) && ((cr3its & USART_CR3_WUFIE) != 0U))