cancel
Showing results for 
Search instead for 
Did you mean: 

Avoid 1 second delay in RTC every power off/on.

Joan Duran
Associate II
Posted on January 03, 2018 at 10:44

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!

#rtc
1 ACCEPTED SOLUTION

Accepted Solutions
Lix Paulian
Senior
Posted on January 04, 2018 at 12:42

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.

View solution in original post

12 REPLIES 12
Posted on January 03, 2018 at 12:43

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

Posted on January 03, 2018 at 16:15

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?

Posted on January 03, 2018 at 17:09

The problem is then, for any reason, the functions HAL_RTC_GetTime() and HAL_RTC_GetDate() doesn't work. So I should do something...

Posted on January 03, 2018 at 17:12

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...

Posted on January 03, 2018 at 17:29

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

Posted on January 04, 2018 at 09:18

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.

Lix Paulian
Senior
Posted on January 04, 2018 at 12:42

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.

Posted on January 04, 2018 at 15:36

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();
Posted on January 06, 2018 at 10:22

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