Skip to main content
Gunnar Bohlen
Associate III
April 22, 2026
Question

CubeMX 6.17.0 generates wrong code for HSE_RTC divider

  • April 22, 2026
  • 1 reply
  • 117 views

Hi,

I'm using STM32H5F5LJHxQ. External HSE Oscillator is 48MHz. RTC clock mux is set to HSE_RTC, divider set to "/48" and the tool shows correctly that RTC clock is 1000kHz (48MHz / 48).

During my tests I discovered a wrong RTC time, error ~2%. (1.2 seconds deviation per minute)

In the generated function HAL_RTC_MspInit() is see: (49 instead of the expected 48)

PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV49;	

If I change the configuration in CubeMX to create a divider of 47, the correct RCC_RTCCLKSOURCE_HSE_DIV47 is generated
If I change the configuration in CubeMX to create a divider of 49, the correct RCC_RTCCLKSOURCE_HSE_DIV49 is. generated.

If I manually set the correct RCC_RTCCLKSOURCE_HSE_DIV48 in the sources, the RTC runs correctly. 

Regards,

Gunnar Bohlen
HMS Networks

 

1 reply

mƎALLEm
Technical Moderator
April 22, 2026

Hello,

Could you please share your ioc file so we could reproduce from our side?

"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."
Gunnar Bohlen
Associate III
April 22, 2026

Hello,

find the ioc file attached.HSR_RTC divider is set to /48.

After code generation the file stm32h5xx_hal_msp.c contains the function

void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc)
{
 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
 if(hrtc->Instance==RTC)
 {
 /* USER CODE BEGIN RTC_MspInit 0 */

 /* USER CODE END RTC_MspInit 0 */

 /** Initializes the peripherals clock
 */
 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV49;
 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
 {
 Error_Handler();
 }

 /* Peripheral clock enable */
 __HAL_RCC_RTC_ENABLE();
 __HAL_RCC_RTCAPB_CLK_ENABLE();
 /* USER CODE BEGIN RTC_MspInit 1 */

 /* USER CODE END RTC_MspInit 1 */

 }

}

 with the clock set to RCC_RTCCLKSOURCE_HSE_DIV49 instead of 48.

mƎALLEm
Technical Moderator
April 22, 2026

Hello,

Thanks for the sharing. I've reproduced the behavior from my side.

I'll report that internally for analysis and eventual fix. Internal ticket for tracking CDM0062030 (not accessible by ST community users).

"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."