Skip to main content
Ogulcan Ariyurek
Associate III
July 19, 2021
Solved

STM32CubeIDE Low Layer (LL) RTC problem in file generator (and my workarond to it)

  • July 19, 2021
  • 2 replies
  • 1209 views

Hi,

I'm using the STM32CubeIDE v1.6.1 and using FW.F2.1.9.3 firmware package with are both currently the lastest up to date versions.

Setting up an STM32CubeMX project for low layer library to be able to use RTC, the code generator is not working properly.

Here is how to generates the code:

/** Initialize RTC and set the Time and Date
 */
 RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR;
 RTC_InitStruct.AsynchPrescaler = 127;
 RTC_InitStruct.SynchPrescaler = 255;
 LL_RTC_Init(RTC, &RTC_InitStruct);
 LL_RTC_SetAsynchPrescaler(RTC, 127);
 LL_RTC_SetSynchPrescaler(RTC, 255);
 /** Initialize RTC and set the Time and Date
 */
 if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) != 0x32F2){
 
 RTC_TimeStruct.Hours = 0;
 RTC_TimeStruct.Minutes = 50;
 RTC_TimeStruct.Seconds = 0;
 LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_TimeStruct);
 RTC_DateStruct.WeekDay = LL_RTC_WEEKDAY_TUESDAY;
 RTC_DateStruct.Month = LL_RTC_MONTH_JULY;
 RTC_DateStruct.Year = 21;
 LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_DateStruct);
 LL_RTC_BAK_SetRegister(RTC,LL_RTC_BKP_DR0,0x32F2);
 }

But here there are two major problems which can be fixed easily by the stm32 developers:

1- Values should be written in hexadecamal format, i.e. 0x50 instead of 50.

2- "Day" is not initialized.

I changed the code as follows to fix it:

RTC_InitStruct.HourFormat = LL_RTC_HOURFORMAT_24HOUR;
	RTC_InitStruct.AsynchPrescaler = 127;
	RTC_InitStruct.SynchPrescaler = 255;
	LL_RTC_Init(RTC, &RTC_InitStruct);
	LL_RTC_SetAsynchPrescaler(RTC, 127);
	LL_RTC_SetSynchPrescaler(RTC, 255);
	/** Initialize RTC and set the Time and Date
	*/
//	if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) != 0x32F2){
 
		RTC_TimeStruct.Hours = 0x1;
		RTC_TimeStruct.Minutes = 0x33;
		RTC_TimeStruct.Seconds = 0x0;
		LL_RTC_TIME_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_TimeStruct);
		RTC_DateStruct.WeekDay = LL_RTC_WEEKDAY_TUESDAY;
		RTC_DateStruct.Day = 0x20;
		RTC_DateStruct.Month = LL_RTC_MONTH_JULY;
		RTC_DateStruct.Year = 0x21;
		LL_RTC_DATE_Init(RTC, LL_RTC_FORMAT_BCD, &RTC_DateStruct);
		LL_RTC_BAK_SetRegister(RTC,LL_RTC_BKP_DR0,0x32F2);
//	}

Also

if(LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR0) != 0x32F2)

statement won't return true so I had to cancel it out.

This topic has been closed for replies.
Best answer by Amel NASRI

Hi @Ogulcan Ariyurek​ ,

Latest version of STM32CubeIDE is 1.7.0. Date parameter is initialized with this version. I suggest you to migrate to this version.

Regarding parameters initialization, I am not sure that they have to be written in hexadecimal format as following assert checks are applied:

#define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
#define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
#define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)

-Amel

2 replies

Amel NASRI
Amel NASRIBest answer
ST Technical Moderator
July 29, 2021

Hi @Ogulcan Ariyurek​ ,

Latest version of STM32CubeIDE is 1.7.0. Date parameter is initialized with this version. I suggest you to migrate to this version.

Regarding parameters initialization, I am not sure that they have to be written in hexadecimal format as following assert checks are applied:

#define IS_LL_RTC_HOUR24(__HOUR__) ((__HOUR__) <= 23U)
#define IS_LL_RTC_MINUTES(__MINUTES__) ((__MINUTES__) <= 59U)
#define IS_LL_RTC_SECONDS(__SECONDS__) ((__SECONDS__) <= 59U)

-Amel

To give better visibility on the answered topics, please click on "Best Answer" on the reply which solved your issue or answered your question.
Ogulcan Ariyurek
Associate III
August 26, 2021

Thanks @Amel NASRI​ ,

I'm currently dealing with another problem, but I will check and report my results ASAP.

Regards,

Ogulcan