2020-04-11 02:02 PM
I seem to be unable to set the time more than once after reset. Here is a way to reproduce my problem:
Or insert this code in your main() function:
/* USER CODE BEGIN 2 */
if (1) {
RTC_TimeTypeDef tm;
HAL_RTC_GetTime(&hrtc, &tm, RTC_FORMAT_BCD);
tm.Hours = 0x06; /* assuming you initialized to something other than 6 */
HAL_RTC_SetTime(&hrtc, &tm, RTC_FORMAT_BCD);
HAL_RTC_GetTime(&hrtc, &tm, RTC_FORMAT_BCD); /* tm.Hours does not change to 6 */
}
/* USER CODE END 2 */
Reading the reference manual, the HAL already issues the CR unlock bytes. I've read some posts about writing the RTC_BKP_DR1 with 0x32f2, but that also does not help (and is not mentioned in the reference manual).
Seems like I'm missing something obvious?
Thanks.
Solved! Go to Solution.
2020-04-11 07:08 PM
I found this on some spanish website for the F439xx HAL, and it fixed the problem:
By adding HAL_RTC_GetDate immediately after the GetTime on line 4 (above), the code works.
Unfortunately, I couldn't find this useful tidbit in the 412KB reference manual.
2020-04-11 07:08 PM
I found this on some spanish website for the F439xx HAL, and it fixed the problem:
By adding HAL_RTC_GetDate immediately after the GetTime on line 4 (above), the code works.
Unfortunately, I couldn't find this useful tidbit in the 412KB reference manual.
2020-04-12 12:46 AM
Thanks for the info!
2020-04-13 04:17 AM
> Unfortunately, I couldn't find this useful tidbit in the 412KB reference manual.
This is the very purpose of having shadow datetime registers at all.
However, FYI, this mechanism is flawed in most STM32, see RTC calendar registers are not locked properly erratum in many STM32 errata. It's hard to tell whether this applies to the 'L412 too - it's latest (and only) errata are dated 2018 while the above erratum is dated late 2016; but ST refuses to publish detailed list of IPs versions used in individual families/models.
JW
PS. It's also documented in Cube in the doxygenoid "header" to HAL_RTC_GetTime(), in the current (April 2020) version https://github.com/STMicroelectronics/STM32CubeL4/blob/master/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rtc.c#L859
2020-04-13 08:35 AM
Ugh... That feeling when asking a question, and then getting the exact file, line, and charater in the comment for the actual function presented to me after having claimed to have read the docs. I could have sworn I RTFM.
Thanks for researching the citations.
2020-04-20 05:04 AM
Its okay. We all do feel like this from time to time... :) Those beast of manuals have thousands of pages for reason.
JW