RTC date update - Problem with VBAT / Low Power Mode
Hi all,
I searched the forum for my specific problem, but i did not find any solution for this weird occurrence. On my STM32F103 i run the RTC, which is working fine, as long as it is connected to the USB power. I store the date on 2 backup registers, which get updated when the date is changed and get read, when the MCU starts. When I set the time for testing purposes to e.g. 23:55, pull out the stm32 board from the main power supply, so that it is powered by VBAT, the date seem to be successfully incremented at 00:00. I check that, by debugging the board a few minutes later. The time works fine in any case. It is just the date that causes problems.
The weird problem, that occurs is the following:
When I power off the board and leave it connected to VBAT overnight, or even multiple days, the date value is not incremented at all. How can it be possible, that 5 minutes in low power mode, triggers a date storage in the backup register, while a full day doesn't?
I'm using the cube IDE with the standard RTC HAL. I tried 2 solutions to extend the RTC code to store the date in the backup register:
- Write the backup register in "stm32f1xx_hal_rtc.c"@"RTC_DateUpdate". Each time the date is updated, this function is called. I just added the code to store the date and it worked.
- I enabled the interrupt for seconds (HAL_RTCEx_RTCEventCallback) and put some conditionals in it, so that the date is always stored, when it updates.
Both derivatives do not work with VBAT connected a longer time (e.g. a day). Please note, that for my purposes, i assume i cannot set the stm32 in the low power mode manually, because it is a "usb stick", that should be unpluggable on demand. Or can I?
Is it possible, that the code in the callback function (2.) is not executed?
I really appreciate any hint or explanation.
Thanks in advance!
