Skip to main content
Visitor II
November 5, 2024
Solved

STM32F103RB RTC Date Not Updating on Power Off with VBAT Enabled

  • November 5, 2024
  • 3 replies
  • 2601 views

Hello everyone,

I'm working with the STM32F103RB controller and have encountered an issue with the RTC functionality. While the time continues to update correctly when powered off (with VBAT enabled), the date resets to the default 01/01/2000 instead of retaining or updating the current date.

Has anyone experienced this behavior before, or can provide guidance on why only the time updates but not the date? Any advice on possible solutions or steps to troubleshoot would be greatly appreciated.

Thank you in advance for your help!

    This topic has been closed for replies.
    Best answer by Techn

    This confusion is expected.. STM32f103 has only a counter, there is no date and day, year etc. From the counter, we need to extract date , month, year etc. The date has to be stored in battery backed up register. Please read the comments in the file

    Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c

     

    ##### WARNING: Drivers Restrictions #####

    ==================================================================

    [..] RTC version used on STM32F1 families is version V1. All the features supported by V2

    (other families) will be not supported on F1.

    [..] As on V2, main RTC features are managed by HW. But on F1, date feature is completely

    managed by SW.

    [..] Then, there are some restrictions compared to other families:

    (+) Only format 24 hours supported in HAL (format 12 hours not supported)

    (+) Date is saved in SRAM. Then, when MCU is in STOP or STANDBY mode, date will be lost.

    User should implement a way to save date before entering in low power mode (an

    example is provided with firmware package based on backup registers)

    (+) Date is automatically updated each time a HAL_RTC_GetTime or HAL_RTC_GetDate is called.

    (+) Alarm detection is limited to 1 day. It will expire only 1 time (no alarm repetition, need

    to program a new alarm)

    3 replies

    Technical Moderator
    November 5, 2024

    Hello @KushalAgrawal @and welcome to the community,

     « While the time continues to update correctly when powered off (with VBAT enabled), the date resets to the default 01/01/2000 instead of retaining or updating the current date. »

    This statement is not clear and there is something contradictory here. It continues to update but the date resets!. Please clarify

    Visitor II
    November 5, 2024

    Thank you for your response. 

    To clarify, here is the issue with a specific example:

    When I turn off the main power at 10:00:00 on 05/11/2024 and then restore power an hour later, the time is correctly retained and updates to 11:00:00. However, the date resets to 01/01/2000 instead of continuing from 05/11/2024.

    So in summary:

    • The time restores and updates correctly (e.g., from 10:00:00 to 11:00:00 after an hour).
    • The date resets to 01/01/2000 instead of continuing from the previously set date (05/11/2024).

    I hope this example clarifies the issue. Please let me know if you need any additional details. Thank you again for your assistance!

    Technical Moderator
    November 5, 2024

    What Hardware are you using? ST board? custom board? Blue/Black pill?

    Visitor II
    November 5, 2024

    Yeah,Thank you for the reminder! I’ve checked the UM1724 reference manual and have removed the SB45 solder bridge as suggested for enabling the coin cell backup.

    KushalAgrawal_0-1730799703434.png

     

    Super User
    November 5, 2024

    While I don't know what exactly causes your problems, generally, both Cube and SPL for 'F1 (which does not have native calendar i.e. time/date  timekeeping in the RTC) use a bizarre mechanism where they use the RTC only to maintain time, and store the datum separately in the backup registers, incrementing it "manually" upon detecting time crossing the 12h/24h boundary.

    I recommend to avoid these libraries and use the RTC natively as an epoch counter and use the standard <time.h> facilities to convert it from/to calendar format.

    JW

    TechnAnswer
    Graduate II
    November 14, 2024

    This confusion is expected.. STM32f103 has only a counter, there is no date and day, year etc. From the counter, we need to extract date , month, year etc. The date has to be stored in battery backed up register. Please read the comments in the file

    Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c

     

    ##### WARNING: Drivers Restrictions #####

    ==================================================================

    [..] RTC version used on STM32F1 families is version V1. All the features supported by V2

    (other families) will be not supported on F1.

    [..] As on V2, main RTC features are managed by HW. But on F1, date feature is completely

    managed by SW.

    [..] Then, there are some restrictions compared to other families:

    (+) Only format 24 hours supported in HAL (format 12 hours not supported)

    (+) Date is saved in SRAM. Then, when MCU is in STOP or STANDBY mode, date will be lost.

    User should implement a way to save date before entering in low power mode (an

    example is provided with firmware package based on backup registers)

    (+) Date is automatically updated each time a HAL_RTC_GetTime or HAL_RTC_GetDate is called.

    (+) Alarm detection is limited to 1 day. It will expire only 1 time (no alarm repetition, need

    to program a new alarm)