2025-07-16 11:56 AM
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?