Skip to main content
Explorer II
January 22, 2023
Question

How to wake up STM32L4 from STOP1 when receiving on USART

  • January 22, 2023
  • 4 replies
  • 4498 views

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!

    This topic has been closed for replies.

    4 replies

    ST Employee
    January 23, 2023

    Hello @Tombedded​ and welcome to the Community :smiling_face_with_smiling_eyes:,

    Can that be the reason?

    >> Yes it can be!

    In fact, as it is mentioned in the AN4635 in section 4.3, in most of the cases the DMA cannot be used in combination with the Stop mode, hence all DMA channels have to be disabled before entering the Stop Low-power mode.

    and also in section 4.4.2 : The downside is that in DMA mode the LPUART cannot take advantage of wakeup from Stop mode.

    TombeddedAuthor
    Explorer II
    January 23, 2023

    Thanks Sarra, good to know. I'm using the USART but I guess the same limitation applies there. To bad DMA is not mentioned in AN4991.

    Then I need to find the answer to my alternate implemention - why there is no EXTI interrupt if I configure the UART RX pin as EXTI. Maybe UART must be disabled before the pin can work as EXTI?

    TombeddedAuthor
    Explorer II
    January 23, 2023

    I now tried call HAL_UART_DeInit() before configuring USART RX pin as EXTI but that did not help. Still no interrupt on falling edge of the pin. Tried the same with a non-USART pin and there I got an interrupt successfully. So is it not possible to reconfigure an USART pin to GPIO/EXTI pin after once configured as USART pin?

    ST Employee
    February 6, 2023

    Hello @Tombedded​ 

    In case it could help, there are some code examples provided in STM32CubeL4 Firmware package that could be of interest. For instance, you could have a look at following example in Projects/NUCLEO-L476RG/Examples/UART/UART_WakeUpFromStop directory of the STM32CubeL4 FW package.

    You could also find it here on Github.

    Regards

    Graduate II
    March 12, 2023
    Graduate
    October 31, 2024

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