Skip to main content
Associate II
August 12, 2025
Question

STM32U5 STOP2 with FreeRTOS

  • August 12, 2025
  • 2 replies
  • 389 views

What should I pay attention to when I use stm32u5 FreeRtos stop2,
W
hen exiting stop2, do the relevant i2c spi adc uart peripherals need to be reinitialized?
Is the value retained?
Is there a routine for FreeRtos stop2?

void Bsp_PowerManage_enter_stop_mode(void)
{
if ((device_state_info.stimulate_state) || (device_state_info.device_ota)) {
return;
}
osKernelLock(); /
while (__HAL_UART_GET_FLAG(&hlpuart1, USART_ISR_BUSY));
while (__HAL_UART_GET_FLAG(&hlpuart1, USART_ISR_REACK) == RESET);
__HAL_RCC_LPUART1_CLKAM_ENABLE();
__HAL_RCC_LPTIM1_CLKAM_ENABLE();
HAL_UARTEx_EnableStopMode(&hlpuart1);
device_lowpower_state.stop_mode_state = 1;
HAL_SuspendTick(); // 
#if Bsp_IWDG
if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, 61438) != HAL_OK)
{
Error_Handler();
}
#endif
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
SystemClock_Config();
HAL_InitTick(TICK_INT_PRIORITY)

if (!__HAL_PWR_GET_FLAG(PWR_FLAG_STOPF)) Error_Handler();
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_STOPF);
if (__HAL_PWR_GET_FLAG(PWR_FLAG_STOPF)) Error_Handler();


#if Bsp_IWDG
HAL_LPTIM_TimeOut_Stop_IT(&hlptim1);
#endif
HAL_UARTEx_DisableStopMode(&hlpuart1);
HAL_UARTEx_ReceiveToIdle_IT(&hlpuart1, uart_recv_data.buf, 512);
device_lowpower_state.stop_mode_state = 0;
osKernelUnlock();
Function_Open_PowerManageTimer();// Open FreeRtos TIME

}

Edited to apply source code formatting - please see How to insert source code for future reference.

This topic has been closed for replies.

2 replies

ST Technical Moderator
August 12, 2025

Hello @caiChangKun 

Several peripheral support the autonomous mode and can run in STOP mode without CPU wakeup. Please refer to the reference manual: 

Saket_Om_1-1754992862003.png

So you don't need to reinitialize these peripheral. 

Below is typical sequence for entering and exiting STOP2 with FreeRTOS:

void Enter_Stop2_Mode(void)
{
 // 1. Prepare peripherals (stop ongoing transfers, etc.)
 // 2. Lock the RTOS kernel
 osKernelLock();

 // 3. Suspend SysTick
 HAL_SuspendTick();

 // 4. Enter STOP2 mode
 HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);

 // 5. Upon wakeup, reconfigure system clock
 SystemClock_Config();

 // 6. Resume SysTick
 HAL_ResumeTick();

 // 8. Unlock the RTOS kernel
 osKernelUnlock();
}

 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om
ST Technical Moderator
August 20, 2025

Hello @caiChangKun 

Any update on this thread please? 

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om