Turn on RTC battery backup

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
rallysjd
Posts: 15
Joined: Mon Jan 16, 2012 4:17 pm

Turn on RTC battery backup

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Turn on RTC battery backup

Post 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
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Turn on RTC battery backup

Post 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.
rallysjd
Posts: 15
Joined: Mon Jan 16, 2012 4:17 pm

Re: Turn on RTC battery backup

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