Skip to main content
Visitor II
August 6, 2025
Solved

RTC Not Working Correctly with FreeRTOS

  • August 6, 2025
  • 2 replies
  • 329 views

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.
    Best answer by TDK

    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.

    2 replies

    TDKAnswer
    Super User
    August 6, 2025

    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.

    LeonSuAuthor
    Visitor II
    August 7, 2025

    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.