Page 1 of 1

Battery backed RTC

Posted: Mon Nov 10, 2014 11:14 am
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?

Re: Battery backed RTC

Posted: Mon Nov 10, 2014 11:46 am
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

Re: Battery backed RTC

Posted: Mon Nov 10, 2014 2:49 pm
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?

Re: Battery backed RTC

Posted: Mon Nov 10, 2014 2:57 pm
by Giovanni
I would like to avoid dependencies between the initialization and the various drivers, it would be messy to handle.

Giovanni

Re: Battery backed RTC

Posted: Tue Nov 11, 2014 9:04 am
by steved
Just to confirm that an incorrect #define STM32_RTCSEL was the problem.