2018-01-03 01:44 AM
Hi again,
I'm using an RTC as I explained in
https://community.st.com/0D50X00009XkWttSAF
.Our device have a battery in VBAT, so the RTC still works when the device it's power off. But after a power on the RTC can loss up to 1 second, I think due we configure the RTC again.
Using backup registers we can detect if we come for the first power on (and we have to configure the RTC) or not (and maybe we can avoid configuring the RTC).
How we can avoid this delay? Which should be the configuration of the RTC in the second case?
Thank you!
#rtcSolved! Go to Solution.
2018-01-04 03:42 AM
This is a known issue. You may want to check this thread, in particular this post:
https://community.st.com/0D50X00009XkgBWSAZ
This is the best way to handle the RTC initialisations. Unfortunately, by default the CubeMX initialises automatically the RTC, so you have to un-check this in a configuration menu and call the appropriate functions as in the example above.
[edit]: You may also take a look here:
https://github.com/lixpaulian/stm32f7-rtc
In particular, check the function
rtc::power
(
bool
state) in thesrc/rtc-drv.cpp file, there you can see how and especially, when to initialise the RTC.
2018-01-03 03:43 AM
How we can avoid this delay? Which should be the configuration of the RTC in the second case?
None - the RTC retains its setting during poweroff, if under battery.
JW
2018-01-03 07:15 AM
due we configure the RTC again
So don't do that, then!
Using backup registers we can detect if we come for the first power on (and we have to configure the RTC) or not (and maybe we can avoid configuring the RTC).
Sounds reasonable - why don't you try it and see?
2018-01-03 09:09 AM
The problem is then, for any reason, the functions HAL_RTC_GetTime() and HAL_RTC_GetDate() doesn't work. So I should do something...
2018-01-03 09:12 AM
How we can avoid this delay? Which should be the configuration of the RTC in the second case?
None - the RTC retains its setting during poweroff, if under battery.
The problem is then, for any reason, the functions HAL_RTC_GetTime() and HAL_RTC_GetDate() doesn't work. So I should do something...
2018-01-03 09:29 AM
EDIT
Enable RTC in respective RCC_APBxENR?
EDIT2
PWR->CR |= PWR_CR_DBP;
(PWR needs to be enabled in RCC prior to this).
This appears not needed for time/date reading. I don't know then...
JW
2018-01-04 12:18 AM
I´m using a backup register to assign a 'magic' value to it and do the initialisation. If after power on the backup register contains this magic number, the init will be skiped. That works fine for my application of STM32L476.
2018-01-04 03:42 AM
This is a known issue. You may want to check this thread, in particular this post:
https://community.st.com/0D50X00009XkgBWSAZ
This is the best way to handle the RTC initialisations. Unfortunately, by default the CubeMX initialises automatically the RTC, so you have to un-check this in a configuration menu and call the appropriate functions as in the example above.
[edit]: You may also take a look here:
https://github.com/lixpaulian/stm32f7-rtc
In particular, check the function
rtc::power
(
bool
state) in thesrc/rtc-drv.cpp file, there you can see how and especially, when to initialise the RTC.
2018-01-04 07:36 AM
Thank you lix! This solved the issue!
Just a curiosity in your code, why you don't enable the clock and backup access? Like this...
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();/* Enable writing RTC back-up registers */
HAL_PWR_EnableBkUpAccess();2018-01-06 02:22 AM
This is done in the HAL function at the end of the following sequence:
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
HAL_RCCEx_PeriphCLKConfig (&PeriphClkInitStruct);
Lix