I'm using a STM32F405.
While playing with the RTC, I discovered that my date/time was cleared at every reboot of my device. I also found that it happens only when using LSE, switching to LSI makes it work (as long as the external power supply is plugged, of course).
Investigating further, I found the reason: when I select LSE, ChibiOS always executes a backup domain reset (hal_lld.c, line 61) because it thinks that the clock source has changed; and indeed, the RCC_BDCR register says that LSI was previously selected, which is of course wrong
So here is my problem: why is the RTCSEL bit of the RCC_BDCR register always reset to "LSI" (0x2) whereas I only use "LSE" (0x1)? This happens whenever I reset the execution. With the debugger, I found that the register has the correct value upon startup, but as soon as the execution reaches the ResetHandler (is there anything between startup and ResetHandler??), the value is already wrong again.
Of course, I have an internal battery which seems to be working fine.
If you need more details, or if I was not clear enough, don't hesitate to ask.