Battery backed RTC

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Battery backed RTC

Post by steved »

I'm trying to implement a battery-backed RTC on an STM32F051 (RTC2 driver).
I've got a 32768Hz crystal connected, which is oscillating.
Using Chibios 3.
I've set STM32_LSECLK to 32768 in the board header file, and STM32_LSE_ENABLED to true in mcuconf.h

According to the RCC->BDCR register, the LSE clock remains disabled, and the RTC is driven from the on-chip 40kHz oscillator (which agrees with my observations - the RTC is running fast).

From what I've read so far, it looks as if I need to change the RTC backup domain, and there's some promising code in hal_lld_backup_domain_init() in hal_lld.c , but I can't see that it's called anywhere.

Is this something that's currently supported?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Battery backed RTC

Post by Giovanni »

Never tested on that specific platform, please verify on the F4 the initialization procedure and call that function on the F0 from the same point.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: Battery backed RTC

Post by steved »

All the 32F devices have basically the same HAL initialisation.

Having looked more closely, I think I missed that #define STM32_RTCSEL needs to be changed from STM32_RTCSEL_LSI to STM32_RTCSEL_LSE
Will test that in the next few days.

Since the LSE clock is mostly used with the RTC (and can only be used with the RTC, on the F0) might it be appropriate to group LSE and RTC functions together in mcuconf.h? Or even auto-enable LSE if its selected as the RTC clock source?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Battery backed RTC

Post by Giovanni »

I would like to avoid dependencies between the initialization and the various drivers, it would be messy to handle.

Giovanni
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: Battery backed RTC

Post by steved »

Just to confirm that an incorrect #define STM32_RTCSEL was the problem.
Post Reply