Page 1 of 1

Turn on RTC battery backup

Posted: Sun Feb 19, 2012 5:10 pm
by rallysjd
Our STM32F103VE board has a battery backup for the RTC ... in hal_lld.c I see

/* PWR and BD clocks enabled. */
rccEnablePWRInterface(FALSE);
rccEnableBKPInterface(FALSE);

Looking at the STM specs these appear to set registers that enable an RTC backup timer. I've tried setting these TRUE, but in both cases while the RTC value is maintained when power is off, it's not being updated, which is what I want to achieve. My understanding is that this should be possible.

I read the above code to mean that PWR and BD are in fact disabled when 2.4 boots. Would you clarify this please?

regards
SD

Re: Turn on RTC battery backup

Posted: Sun Feb 19, 2012 5:27 pm
by Giovanni
Hi,

Are you sure that the external 32K oscillator works while the device is under battery power? it is possible it is not running and the RTC does not increase.

Giovanni

Re: Turn on RTC battery backup

Posted: Sun Feb 19, 2012 5:48 pm
by barthess
Hi
rallysjd wrote:/* PWR and BD clocks enabled. */
rccEnablePWRInterface(FALSE);
rccEnableBKPInterface(FALSE);

That code just enable access to RTC registers via AHB1 bus, it not starts RTC cell. RTC enables in halInit() function. Did you forget about

Code: Select all

#define HAL_USE_RTC                 TRUE

Switching argument of rccEnablePWRInterface(FALSE); to TRUE enables power saving mode.

Re: Turn on RTC battery backup

Posted: Tue Feb 28, 2012 4:06 pm
by rallysjd
Found it. Here's how to get it working.
In mcuconf.h

the internal high speed clock is the default for the RTC tick over. This has to be changed to use the external 32KHz clock.

#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED TRUE

#define STM32_RTCSEL STM32_RTCSEL_LSE // was STM32_RTCSEL_HSEDIV

With STM32_RTCSEL_HSEDIV used, the RTC value is retained when the board power is removed, but the clock does not tick over on battery power.

SD.