Skip to main content
Joan Duran
Associate II
January 3, 2018
Solved

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

  • January 3, 2018
  • 5 replies
  • 3609 views
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
This topic has been closed for replies.
Best answer by Lix Paulian
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.

5 replies

waclawek.jan
Super User
January 3, 2018
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

Joan Duran
Associate II
January 3, 2018
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...

Andrew Neil
Super User
January 3, 2018
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?

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
info239955_stm1_stmicro
Associate
January 4, 2018
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
Lix PaulianBest answer
Associate II
January 4, 2018
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.

Joan Duran
Associate II
January 4, 2018
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();
Lix Paulian
Associate II
January 6, 2018
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

WKose
Visitor II
November 19, 2018

Hi,

any updates on HAL RTC?

Sincerely,

Wojciech