STM32CubeIDE Low Layer (LL) RTC problem in file generator (and my workarond to it)
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.
