[SOLVED]Unwanted RTC reset at reboot

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

Moderator: RoccoMarco

Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

[SOLVED]Unwanted RTC reset at reboot

Post by Laurent »

Hi

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

Re: Unwanted RTC reset at reboot

Post by Giovanni »

Probably Barthess can explain the problem, I'll wait his opinion first before attempting a fix.

Giovanni
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Unwanted RTC reset at reboot

Post by barthess »

Laurent
I will check it this evening. Also, it will be good to speak with you on at #chibios channel irc.freenode.net
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Unwanted RTC reset at reboot

Post by Laurent »

Thanks.

I'm hardly available for live chat, but we can discuss here or by e-mail, I'll do my best to always answer quickly.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Unwanted RTC reset at reboot

Post by barthess »

I observe such RTC resets when resets MCU using openocd command "monitor reset halt". Changing it to "monitor soft_reset_halt" fix RTC resets but not allways correctly stops the core.

Write simple application sending time value to UART and try to reset board with reset pin or power cycle.
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Unwanted RTC reset at reboot

Post by Laurent »

I already wrote such an application, that outputs the time at startup, and I have tried all kind of resets, none of them works. I don't think I have a reset pin available (it's a custom board, not a development one), but both power cycle and soft reset (SCB_AIRCR = (AIRCR_VECTKEY | (SCB_AIRCR & (0x700)) | (1 << 2))) produce the same incorrect result.
User avatar
alex31
Posts: 445
Joined: Fri May 25, 2012 10:23 am
Has thanked: 57 times
Been thanked: 88 times

Re: Unwanted RTC reset at reboot

Post by alex31 »

I use same mcu, on olimex (rtc backup with battery) and custom design (rtc backup via super capacitor, sufficient for 3 days), and never notice
that problem using LSE.

rtc keep value over power cycling, reset, and watchdog reset.

the only problem we had on the custom board was to find compatible cms quartz and capacitor to make lse beat.

Alexandre
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Unwanted RTC reset at reboot

Post by barthess »

Laurent
Can you check (with oscilloscope for example) your LSE running good without main supply?
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Unwanted RTC reset at reboot

Post by Laurent »

I'll check that as soon as I can.
Laurent
Posts: 35
Joined: Mon Mar 25, 2013 9:01 am

Re: Unwanted RTC reset at reboot

Post by Laurent »

I checked the LSE with an oscilloscope, it runs fine without the main supply.

Something important to remember: the RTC registers are correctly preserved when I reboot, so it's most likely not a power supply issue. It's just the RTCSEL bits of the RCC_BDCR register which always reset to "LSI", making ChibiOS trigger a backup domain reset; if I comment out lines 61-62 in hal_lld.c the clock is not reset after rebooting.
Post Reply