2025-07-16 11:56 AM - last edited on 2025-07-17 6:29 AM by Andrew Neil
I used STM32CubeMX to generate code for the STM32U083 following the instructions in Lab 3 of the STM32U0 Workshop presentation (V2.3, last modified Fri 12 Jul 2024 09:51:37 AM ). One of the steps in the lab is to set the RTC configuration on page 102.
Upon code generation, this value appears at the end of MX_RTC_Init() in the following code snippet:
/** Enable the WakeUp
*/
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 10246, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0) != HAL_OK)
{
Error_Handler();
}
The lab then goes on to instruct the user to include the very same code snippet in the main loop:
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_WritePin(GPIOA, GPIO_Pin_5, GPIO_PIN_SET);
HAL_Delay(1000);
HAL_GPIO_WritePin(GPIOA, GPIO_Pin_5, GPIO_PIN_RESET);
HAL_SuspendTick();
if ( HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 10246, RTC_WAKEUPCLOCK_RTCCLK_DIV16, 0) != HAL_OK)
{
Error_Handler();
}
HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
HAL_ResumeTick();
SystemClock_Config();
/* USER CODE END WHILE */
OK, so no problem so far, the code compiles and runs on my NUCLEO-U083RC as expected.
First question: Why is the line duplicated? Is there some reason the RTC needs to be enabled each time the loop iterates?
Second question: I repeated the same process on a NUCLEO-L452RE-P but, for some reason, the Wake Up Counter value entry in the CubeMX's RTC Configuration Parameter Settings seems to be ignored (i.e. the call to HAL_RTCEx_SetWakeUpTimer_IT() in MX_RTC_Init() isn't present in the L4x generated code.) Is there a particular reason for this?
2025-09-01 6:40 AM
Hello @AMacd.1 ;
First of all, I apologize for my late reply.
Are you using the same version of STM32CubeMX as the one presented in the STM32U0 workshop?
Are you encountering an issue when commenting the duplication in the while loop?
For the second issue I reported internally.
Internal ticket number: 216642 (This is an internal tracking number and is not accessible or usable by customers).
Thank you.
Kaouthar
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.
2025-09-08 7:03 AM
@KDJEM.1 : Thanks for replying. Here are the answers to your questions:
Q1. Are you using the same version of STM32CubeMX as the one presented in the STM32U0 workshop?
A: No. I am trying to adopt the workshop to the most recent CubeMX. Also, I am trying to apply the principle in the workshop to a different processor: STM32l451RETx
Q2: Are you encountering an issue when commenting the duplication in the while loop?
A: I did not see any problems at all when taking the HAL_RTCEx_SetWakeUpTimer_IT() call out of the main loop.
Cheers,
Allan
2025-09-16 9:12 AM - edited 2025-09-16 9:13 AM
Hello @AMacd.1 ;
Thank you for updating post.
For STM32L4, I recommend you to follow the steps shared in this article How to configure the RTC to wake up the STM32 periodically from Low Power modes. In this article we will see how to configure the RTC peripheral of the STM32 to wake up the STM32 periodically from a low power mode like STOP2 mode which is one of the lowest power modes of the STM3L4.
The STM32CubeMX version used in the STM32U0 workshop is very old, I think it is STM32CubeMX issue.
Thank you for your contribution in STCommunity
Kaouthar
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.