2019-10-24 06:14 AM
I've designed a board that has a STM32L476.
This part is supplied using a triple system of dual battery + power ( when it is available)
We've manufactured more than 20k units of them and they are working ok
A few days ago 2 boards came back to our design lab that exhibit the following symptoms :
-> The RTC keeps counting past 23:59:59 until 39:59:59
-> Neither on 23h nor 39h rollover the day gets increased
-> When trying to set the time we get the following data:
If the time is less than 20h, 20h get added to it
Else the hour is correctly set
-> Rollover behavior don't changes
If we force a reset of the CPU, the problem dissapears.
More data:
-> The RTC access is done using HAL libs.
-> The RTC isn't reset when setting the date/time
We still have one untouched board for testing, but any try to use a debugger would trigger a CPU reset, making the probblem dissapear. (This is why we lost ont of the boards )
Does anybody have a hint about what the problem could be ?
2023-01-29 10:25 AM
Yes the sDate and sTime variables are local. My application uses FreeRTOS and these variables are declared outside the forever loop. In this case I understand the initialization is called only once, right?
That is the reason I am adding the parameters initialization inside the forever loop, just before the date and time update.
I am following the discussion here about root cause related to uninitialized parameters...
My problem is exactly the same as in this thread, RTC is counting more than 24h...
My hardware is the STM32L433CB.
Thank you,
Iaran
2023-01-31 06:01 AM
Details do matter. If the structs are initialized to zero and then never changed (except the time and date itself), the "problematic" fields remain to be zero so they should not cause problem even without the explicit zeroing.
JW
2023-01-31 12:24 PM
How can we address this topic to the ST HAL development team? A correction could be implemented directly in the HAL code.
I see there are other HAL structs, for ADC, UART, I2C... Is this initialization issue also present in those structs?
Thank you,
Iaran
2023-02-01 02:37 AM
Root of the problem is, that users call the Cube/HAL functions with incorrectly set parameters (struct fields - having them as uninitialized local variables is only one way how they can be set incorrectly).
I don't understand how could Cube/HAL fix something which is user error.
JW
2023-02-01 05:47 PM
It seems I misunderstood the answer from @albert2, saying the "The HAL lib doesn't mask the bit fields before writing the data to the RTC registers".
For me it was some HAL Lib problem.
If the solution is just to initialize ALL struct members than it should be fine for my application now.
Orinally, I was not using/not updating these two parameters: SubSeconds and SecondFraction.
Do you think this could be the reason for the RTC hours counting going more than 24h?
Thanks.
EDITED: Just happened again. Today morning I see the hours showing 26! I still don´t get real root cause for this problem...
2023-02-02 03:37 AM
> It seems I misunderstood the answer from @albert2 (Community Member), saying the "The HAL lib
> doesn't mask the bit fields before writing the data to the RTC registers".
> For me it was some HAL Lib problem.
I am not really willing to discuss Cube/HAL issues, I don't use it and I think it's simply a waste of time.
Nonetheless, masking bitfileds won't help with uninitialized struct fields as they may have unwanted ones (note, uninitialized means random content) at the places which are unmasked.
> Just happened again. Today morning I see the hours showing 26!
> I still don´t get real root cause for this problem...
The very first thing to do when you encounter this sort of problems is to read out and check the RTC registers content.
Then check all places where you write into RTC, whether all registers are written as intended. Note, that at this moment you should consider Cube/HAL code as your own and debug it as such.
JW
2023-02-02 05:35 AM
For me, one of the more serious sources of the problem is the way in which CubeMX creates the code and how HAL examples are written in all the ST demos.
This is an example of the error-prone ST style:
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO pin : CEC_CK_MCO1_Pin */
GPIO_InitStruct.Pin = CEC_CK_MCO1_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF0_MCO;
HAL_GPIO_Init(CEC_CK_MCO1_GPIO_Port, &GPIO_InitStruct);
And that's how it should be written to educate the users:
static const GPIO_InitTypeDef GPIO_InitStruct = {
/*Configure GPIO pin : CEC_CK_MCO1_Pin */
.Pin = CEC_CK_MCO1_Pin,
.Mode = GPIO_MODE_AF_PP,
.Pull = GPIO_NOPULL,
.Speed = GPIO_SPEED_FREQ_LOW,
.Alternate = GPIO_AF0_MCO
}
HAL_GPIO_Init(CEC_CK_MCO1_GPIO_Port, &GPIO_InitStruct);
This way:
There is one problem with this approach. Most of HAL creators don't understand the importance of const specifier in pointer-to-structure arguments, so most of HAL functions don't like constant arguments which they incorrectly believe to be variables. This is a well-known serious issue of HAL code.
2023-03-29 03:13 PM
I have the same problem with a B-U585I-IOT board.
Days never increase and hours keep increasing...
Try all the above suggestions... none worked
Something new ?
thanks
2023-03-29 03:30 PM
Sorry, this works:
sDate.WeekDay = RTC_WEEKDAY_WEDNESDAY;
sDate.Date = 31;
sDate.Month = RTC_MONTH_DECEMBER;
sDate.Year = 23;
sTime.SubSeconds = 0;
sTime.SecondFraction = 0;
sTime.TimeFormat = RTC_FORMAT_BIN;
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
sTime.Hours = 23;
sTime.Minutes = 59;
sTime.Seconds = 55;
__HAL_RTC_WRITEPROTECTION_DISABLE(&hrtc);
RTC_EnterInitMode(&hrtc);
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK) {
printf("Error Setting Time !\n");
}
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK) {
printf("Error Setting Date !\n");
}
RTC_ExitInitMode(&hrtc);
__HAL_RTC_WRITEPROTECTION_ENABLE(&hrtc);
HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR0, 0x1234); // Date & Time are set
The day, month & year are incremented 5 seconds later
2024-01-28 08:41 PM