Page 1 of 1

STM32F1xx RTC date problem

Posted: Sun Nov 15, 2020 7:57 am
by saeed144
Hi everyone
I heard HAL function in STM32F1xx series have a bug in RTC! when micro reset time value is correct but date value reset too and show 0
there are some modification stm32f1xx_hal_rtc to solve this problem, but what about Arduino IDE?
Howto solve this problem in Arduino_IDE?

Re: STM32F1xx RTC date problem

Posted: Sun Nov 15, 2020 12:15 pm
by GonzoG
It's not a bug. RTC in F1 doesn't support calendar so date is kept only till it's powered down or reset.

Re: STM32F1xx RTC date problem

Posted: Sun Nov 15, 2020 3:53 pm
by saeed144
You mean there is no solution? :cry:

Re: STM32F1xx RTC date problem

Posted: Sun Nov 15, 2020 10:30 pm
by mrburnette
saeed144 wrote: Sun Nov 15, 2020 7:57 am Hi everyone
I heard HAL function in STM32F1xx series have a bug in RTC! when micro reset time value is correct but date value reset too and show 0
there are some modification stm32f1xx_hal_rtc to solve this problem, but what about Arduino IDE?
Howto solve this problem in Arduino_IDE?
Is this "hypothetical" or have you experienced the issue?
IMO, hypothetical concerns mean you need to do a test/experiment.

Arduino core by STM rides on top (wrapper) so the underlying core code used by Arduino is HAL/LL/CMSIS
https://github.com/stm32duino/Arduino_Core_STM32
This porting is based on:

STM32Cube MCU Packages including:
- The HAL hardware abstraction layer, enabling portability between different STM32 devices via standardized API calls
- The Low-Layer (LL) APIs, a light-weight, optimized, expert oriented set of APIs designed for both performance and runtime efficiency
- CMSIS device defintion for STM32

CMSIS: Cortex Microcontroller Software Interface Standard (CMSIS) is a vendor-independent hardware abstraction layer for the Cortex®-M processor series and defines generic tool interfaces. It has been packaged as a module for Arduino IDE: https://github.com/stm32duino/ArduinoModule-CMSIS

GNU Arm Embedded Toolchain: Arm Embedded GCC compiler, libraries and other GNU tools necessary for bare-metal software development on devices based on the Arm Cortex-M. Packages are provided thanks The xPack GNU Arm Embedded GCC: https://github.com/xpack-dev-tools/arm- ... -gcc-xpack

Re: STM32F1xx RTC date problem

Posted: Mon Nov 16, 2020 3:37 pm
by ag123
saeed144 wrote: Sun Nov 15, 2020 3:53 pm You mean there is no solution? :cry:
connect VBAT to a 3v coin cell, keeps time for a long time

Re: STM32F1xx RTC date problem

Posted: Mon Nov 16, 2020 4:13 pm
by mlundin
The STM32F1xx RTC only has one register that normally counts seconds, using the count of seconds modulo 86400 (number of seconds in a day) it can keep track of the time of day, when this count gets larger than 86400 we know that one day has passed. There is no information in the RTC hardware about the what day, date, year and month. So the HAL layer and the application must handle the date in software and to survive resets of the processor the date must in some way be saved in nonvolatile memory.

The HAL layer as it is used in STM32Duino does not support date saving across STOP and STANDBY.
Quote from stm32f1xx_hal_rtc in the STM32duino distribution
(+) 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)
This is not a bug, its an early version of the RTC hardware and this is how it works.
Perhaps you can locate the example mentioned in the HAL quote above.

Re: STM32F1xx RTC date problem

Posted: Tue Nov 17, 2020 6:08 am
by saeed144
ag123 wrote: Mon Nov 16, 2020 3:37 pm
saeed144 wrote: Sun Nov 15, 2020 3:53 pm You mean there is no solution? :cry:
connect VBAT to a 3v coin cell, keeps time for a long time
it keeps only time not date

Re: STM32F1xx RTC date problem

Posted: Tue Nov 17, 2020 6:08 am
by saeed144
mlundin wrote: Mon Nov 16, 2020 4:13 pm The STM32F1xx RTC only has one register that normally counts seconds, using the count of seconds modulo 86400 (number of seconds in a day) it can keep track of the time of day, when this count gets larger than 86400 we know that one day has passed. There is no information in the RTC hardware about the what day, date, year and month. So the HAL layer and the application must handle the date in software and to survive resets of the processor the date must in some way be saved in nonvolatile memory.

The HAL layer as it is used in STM32Duino does not support date saving across STOP and STANDBY.
Quote from stm32f1xx_hal_rtc in the STM32duino distribution
(+) 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)
This is not a bug, its an early version of the RTC hardware and this is how it works.
Perhaps you can locate the example mentioned in the HAL quote above.
Thank you