2026-04-24 6:05 AM - last edited on 2026-04-24 6:41 AM by mƎALLEm
Hello, I am currently using the NUCLEO-U545RE-Q and trying to set low-power modes with FreeRTOS. I have already seen videos from official ST channel and read documentation but I cannot get to set this functioning when using FreeRTOS and RTC. My goal is to blink an LED every 5 seconds and in the reamaining time go to STOP mode for low power consumption. This are my functions:
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN defaultTask */
/* Infinite loop */
while(1)
{
osSemaphoreAcquire(BinarySemaphoreHandle, osWaitForever);
printf("Toggle Led\n");
BSP_LED_Toggle(LED_GREEN);
}
/* USER CODE END defaultTask */
}
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
printf("RTC Callback\n");
osSemaphoreRelease(BinarySemaphoreHandle);
}
void PreSleepProcessing(uint32_t ulExpectedIdleTime)
{
HAL_SuspendTick();
/* Start low power timer */
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 2000, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0) != HAL_OK)
{
Error_Handler();
}
/* Enter STOP2 */
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
void PostSleepProcessing(uint32_t ulExpectedIdleTime)
{
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
SystemClock_Config();
/* Resume HAL timebase */
HAL_ResumeTick();
}
When I add the code inside PreSleep and PostSleep the LED simply does not blink. From printing debug, the application is always going to PreSleep and PostSleep non-stop and the RTC callback does not get fired. Can someone help me with this?
Best regards.
2026-04-27 2:13 AM
Hello @JPortilha ,
I think the key issue is that PostSleepProcessing() can run after any wakeup, not only after the RTC wakeup you intended.
In the FreeRTOS tickless flow, the sequence is roughly:
So, if there is another interrupt source waking the MCU before the RTC expires, PostSleepProcessing() will still run, and if you call HAL_RTCEx_DeactivateWakeUpTimer() there, you may be disabling the RTC wakeup before it ever gets a chance to fire and release the semaphore. That would match what you are seeing: the code keeps cycling through pre-sleep and post-sleep, but the RTC callback never executes.
I would suggest checking two things:
Please let me know how it works out for you,
Kind regards,
DHIF Khaled
2026-04-27 9:46 AM
Hello, I have changed the code a little bit. I now have this:
/* USER CODE BEGIN PREPOSTSLEEP */
void PreSleepProcessing(uint32_t ulExpectedIdleTime)
{
/* place for user code */
HAL_PWREx_EnableUltraLowPowerMode();
HAL_SuspendTick();
/* Start RTC */
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 20000, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0) != HAL_OK)
{
Error_Handler();
}
/* Enter Stop2 mode, wake up on interrupt */
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
}
void PostSleepProcessing(uint32_t ulExpectedIdleTime)
{
/* place for user code */
/* Restore Clock settings */
SystemClock_Config();
/* Resume HAL timebase */
HAL_ResumeTick();
}
void StartDefaultTask(void *argument)
{
/* USER CODE BEGIN defaultTask */
/* Infinite loop */
for(;;osSemaphoreAcquire(appBinarySemHandle, osWaitForever))
//while(1)
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
}
/* USER CODE END defaultTask */
}
/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
{
osSemaphoreRelease(appBinarySemHandle);
}Seems to be working, but my current consumption is around 30uA, when the datasheet says it should be around 3 or 4uA. Do you know what can be causing such high consumption?
BR.
2026-04-28 2:23 AM
Hello @JPortilha ,
Glad to hear that the default task is now running correctly. Your RTC/semaphore flow looks much closer to working as expected. If the LED is toggling properly but the current consumption is still high, I would suspect one of two things:
A few points are worth checking:
So, at this stage I would mainly check for a periodic wake source and confirm the current is being measured on the MCU supply path only, not the full NUCLEO board path.
Kind regards,
DHIF Khaled
2026-04-28 3:38 AM
Hello, I have analyzed the PCB layout (using the CAD documentation provided by the ST), and I am measuring the current using an external power supply with measuring capabilities (SMU). I have removed the JP5 and JP4 of NUCELO-U545RE-Q and I am supplying through JP5 pin 1. According to the layout on Altium, this pin will only supply the MCU, so I think that part should be ok. I have added prints for debugging and the system seems to only be entering and exiting the low power states every 10 seconds (driven by RTC). I have also added this line after peripheral init to disable the debugger
HAL_DBGMCU_DisableDBGStopMode();I can leave a print of my current measurement, but according to datasheet STOP2 mode with RTC at 3.3V should be around 3.5uA.
BR