cancel
Showing results for 
Search instead for 
Did you mean: 

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

Ogulcan Ariyurek
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Amel NASRI
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Amel NASRI
ST Employee

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 Accept as Solution on the reply which solved your issue or answered your question.

Ogulcan Ariyurek
Associate II

Thanks @Amel NASRI​ ,

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

Regards,

Ogulcan