Skip to main content
Associate II
Aug 6, 2025 3:02 AM UTC
Solved

RTC Not Working Correctly with FreeRTOS

Hello everyone!

We are trying to enable the RTC with FreeRTOS on the STM32U575AII6. The settings are as follows:

1.RCC

LeonSu_1-1754446923860.png

2.RTC

LeonSu_2-1754447015510.png

3.Clock

LeonSu_3-1754447140369.png

4.freeRTOS

LeonSu_4-1754447353395.png

Code

void Debug_Printf(char *format, ...)
{
	char buf[128];

	va_list args;
	va_start(args, format);
	uint16_t len = vsnprintf((char *)buf, sizeof(buf), (char *)format, args);
	va_end(args);
	HAL_UART_Transmit(&huart1 ,(uint8_t *)buf,len,150);
}

void RTCTask(void *argument)
{
 /* USER CODE BEGIN RTC_TASK */
	RTC_DateTypeDef Date;
	RTC_TimeTypeDef Time;
 /* Infinite loop */
 for(;;)
 {
	HAL_RTC_GetTime(&hrtc, &Time, RTC_FORMAT_BIN);
	HAL_RTC_GetDate(&hrtc, &Date, RTC_FORMAT_BIN);
	Debug_Printf("%02d:%02d:%02d\n",Time.Hours, Time.Minutes, Time.Seconds);
	osDelay(1000);
 }
 /* USER CODE END RTC_TASK */
}

 and the result output

"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:01\n"
"10:10:02\n"
"10:10:02\n"
"10:10:02\n"
"10:10:02\n"
"10:10:02\n"

The seconds displayed above are wrong.

Any suggestions would be greatly appreciated. Thanks in advance!

 

 

 

 

 

 

 

This topic has been closed for replies.
TDK
TDKBest answer
Aug 6, 2025 3:56 AM UTC

Is the rate of printing (once per second) correct?

If you clock it with LSI, does it work as expected? If so, LSE isn't working right.

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

TDK
TDKBest answer
Aug 6, 2025 3:56 AM UTC

Is the rate of printing (once per second) correct?

If you clock it with LSI, does it work as expected? If so, LSE isn't working right.

"If you feel a post has answered your question, please click ""Accept as Solution""."
LeonSuAuthor
Associate II
Aug 7, 2025 1:24 AM UTC

Thanks @TDK 

1. Is the rate of printing (once per second) correct?

YES.

2.If you clock it with LSI, does it work as expected? If so, LSE isn't working right.

I tried to switch the RTC clock source to LSI, and it’s working well.
Thanks again.