cancel
Showing results for 
Search instead for 
Did you mean: 

How to wake up STM32L4 from STOP1 when receiving on USART

Tombedded
Associate II

I have read AN4991 and the example code but in my case nothing works. I'm using DMA transfer with the UART. Can that be the reason? Is it not possible to wake up from STOP1 when using DMA to receive bytes from USART? Or how can it be done?

I use CubeMX to initialize peripherals but my "going to sleep" code is esentially like this:

__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
HAL_SuspendTick();
while(__HAL_UART_GET_FLAG(&huart1, USART_ISR_BUSY) == SET);
while(__HAL_UART_GET_FLAG(&huart1, USART_ISR_REACK) == RESET);
UART_WakeUpTypeDef WakeUpSelection;    
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_STARTBIT;
HAL_UARTEx_StopModeWakeUpSourceConfig(&huart1, WakeUpSelection);
__HAL_UART_ENABLE_IT(&huart1, UART_IT_WUF);
HAL_UARTEx_EnableStopMode(&huart1);
HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI);
 
// After USART RX start bit we should wake up from stop and continue here - but it never happens
 
HAL_UARTEx_DisableStopMode(&huart1);
__HAL_UART_DISABLE_IT(&huart1, UART_IT_WUF);
HAL_ResumeTick();

Then I tried another approach. Configuring the UART RX pin as EXTI. Then I would lose the first byte but the transmitter could send a dummy byte to wake the receiver. This approach did not wake the system up either. Code as below:

while(__HAL_UART_GET_FLAG(&huart1, USART_ISR_BUSY) == SET);
while(__HAL_UART_GET_FLAG(&huart1, USART_ISR_REACK) == RESET);
 
// Configure UART RX pin as GPIO input that triggers interrupt on falling edge
GPIO_InitTypeDef GPIO_InitStruct = {
       .Pin = RX_Pin, // GPIO pin 10
       .Mode = GPIO_MODE_IT_FALLING, // Interrupt on falling edge
       .Pull = GPIO_NOPULL,
       .Speed = GPIO_SPEED_FREQ_VERY_HIGH
};
 
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
HAL_SuspendTick();
HAL_PWREx_EnterSTOP1Mode(PWR_STOPENTRY_WFI); 
 
// After interrupt we should wake up from stop and continue here - does not happen
 
HAL_ResumeTick();
HAL_NVIC_DisableIRQ(EXTI15_10_IRQn);
GPIO_InitTypeDef GPIO_InitStruct = {
       .Pin = RX_Pin,
       .Mode = GPIO_MODE_AF_PP,
       .Pull = GPIO_NOPULL,
       .Speed = GPIO_SPEED_FREQ_VERY_HIGH,       
       .Alternate = GPIO_AF7_USART1
};
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);  // restore USART RX on this pin

For this I made EXTI handlers:

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {}
 
void EXTI15_10_IRQHandler(void) {}

I'll be grateful for any help I can get with this. Thanks!

10 REPLIES 10
AlfRomeo
Associate III

Did you finally solve it? I am also facing this problem now