2024-09-19 02:04 AM
Hi,
Using references from
1) STML496 UART Wake up from Stop Example - https://github.com/STMicroelectronics/STM32CubeL4/blob/master/Projects/NUCLEO-L496ZG/Examples/UART/UART_WakeUpFromStop/Src/main.c#L78
2) STM Getting started with PWR Guide - https://wiki.st.com/stm32mcu/wiki/Getting_started_with_PWR#Stop0.2C_Stop1.2C_and_Stop2_modes
I have the following code that tries to wake up from STOP1 via UART.
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_UART5_Init();
/* USER CODE BEGIN 2 */
HAL_PWREx_EnableLowPowerRunMode();
/* USER CODE END 2 */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);
/* make sure that no UART transfer is on-going */
while(__HAL_UART_GET_FLAG(&huart5, UART_FLAG_BUSY) == SET);
/* make sure that UART is ready to receive
* (test carried out again later in HAL_UARTEx_StopModeWakeUpSourceConfig) */
while(__HAL_UART_GET_FLAG(&huart5, UART_FLAG_REACK) == RESET);
WakeUpSelection.WakeUpEvent = UART_WAKEUP_ON_READDATA_NONEMPTY;
if (HAL_UARTEx_StopModeWakeUpSourceConfig(&huart5, WakeUpSelection)!= HAL_OK)
{
Error_Handler();
}
/* Enable the UART Wake UP from STOP1 mode Interrupt */
__HAL_UART_ENABLE_IT(&huart5, UART_IT_WUF);
/* enable MCU wake-up by UART */
HAL_UARTEx_EnableStopMode(&huart5);
/* enter STOP1 mode */
DEBUG_Transmit((uint8_t *)"Entering stop mode\r\n", 20);
HAL_SuspendTick();
HAL_PWREx_EnterSTOP1Mode(PWR_SLEEPENTRY_WFI);
HAL_ResumeTick();
DEBUG_Transmit((uint8_t *)"success\r\n", 9);
/* at that point, MCU has been awoken: the LED has been turned back on */
SystemClock_Config();
/* Wake Up based on RXNE flag successful */
HAL_UARTEx_DisableStopMode(&huart5);
However, the interrupt does not seem to trigger and i am always stuck in stop mode.
I have also attached my clock configuration as follows.
Appreciate any advise on what I am doing wrong. Thank you.
Solved! Go to Solution.
2024-09-20 01:11 AM
Solved this by adjusting clock to not use MSI, though this is not an optimal solution as i would prefer a lower clock speed configuration for my usage. Will try to see how i can modify the code to work with MSI clock configuration.
2024-09-19 03:00 AM
Hello @jlsw30, welcome to ST Community,
To be sure that the UART is not busy with any ongoing transmission or reception and the UART receiver is enabled and ready to receive data:
while(__HAL_UART_GET_FLAG(&UartHandle, USART_ISR_BUSY) == SET);
/* make sure that UART is ready to receive
* (test carried out again later in HAL_UARTEx_StopModeWakeUpSourceConfig) */
while(__HAL_UART_GET_FLAG(&UartHandle, USART_ISR_REACK) == RESET)
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2024-09-19 06:55 PM
Hello Sarra, thank you for the reply.
Initially thought I had to use a different flag as it was UART5 instead of USART5 on STML4A6.
Either way, I have tried the code as recommmended but was still unable to wake up from stop mode.
while(__HAL_UART_GET_FLAG(&UartHandle, USART_ISR_BUSY) == SET);
/* make sure that UART is ready to receive
* (test carried out again later in HAL_UARTEx_StopModeWakeUpSourceConfig) */
while(__HAL_UART_GET_FLAG(&UartHandle, USART_ISR_REACK) == RESET)
In the datasheet, UART 5 is able to wake stop1, so i believe that it should be possible
I have also attached my callbacks as follows for reference:
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == UART5)
{
HAL_ResumeTick();
/* at that point, MCU has been awoken: the LED has been turned back on */
SystemClock_Config();
/* Handle received data */
DEBUG_Transmit((uint8_t *)"Data received\r\n", 15);
}
}
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == UART5)
{
DEBUG_Transmit((uint8_t *)"Data transmitted\r\n", 18);
}
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == UART5)
{
DEBUG_Transmit((uint8_t *)"UART Error\r\n", 12);
}
}
Thank you!
2024-09-19 07:45 PM - edited 2024-09-19 10:56 PM
2024-09-20 01:11 AM
Solved this by adjusting clock to not use MSI, though this is not an optimal solution as i would prefer a lower clock speed configuration for my usage. Will try to see how i can modify the code to work with MSI clock configuration.