Solution how to fix broken RTC on Nucleo_F103RB / STM32F103 BluePill etc..

Dependencies:   mbed-dev

Fork of Nucleo_RTC_battery_bkup_pwr_off_okay by Kenji Arai

Experimental fork https://os.mbed.com/users/kenjiArai/code/Nucleo_RTC_battery_bkup_pwr_off_okay/ to fix broken RTC on Nucleo_F103RB / STM32F103 BluePill etc..

At this moment (7/11/17) use forked mbed-dev https://os.mbed.com/users/maxxir/code/mbed-dev/.

Or require patch for ./mbed-dev/targets/TARGET_STM/rtc_api.c.

You can manual add to your project fresh mbed-dev and change file mbed-dev\targets\TARGET_STM\rtc_api.c from root project patched rtc_api.c.stm32f10x.txt.

Exploring origin errors, I saw that something wrong with HAL API on STM32F1xx with this functions:

 HAL_RTC_GetTime(&RtcHandle, &timeStruct, RTC_FORMAT_BIN);

 HAL_RTC_GetDate(&RtcHandle, &dateStruct, RTC_FORMAT_BIN);


 HAL_RTC_SetDate(&RtcHandle, &dateStruct, RTC_FORMAT_BIN);

 HAL_RTC_SetTime(&RtcHandle, &timeStruct, RTC_FORMAT_BIN);

Look here (as I understand it possible broken on STM32CUBE HAL level now):

https://community.st.com/thread/43218-stm32f103-loss-rtc-date-when-reset

So I use direct RTC register manipulation for STM32F1xx:

rtc_read(), rtc_write() (native rtc_init() - works good).

Also added stub for non-working on STM32F1xx rtc_read_subseconds().

Now the stm32F103 can survive power off, and allows you to get and set the time.

Tested OK on boards:

NUCLEO STM32F103RB, DIY STM32F100CB (forked from DISCO_F100RB)

Happy coding!

maxxir

10/11/17

History

Addded patched and renamed rtc_api.c to root of prj default tip

2017-11-10, by maxxir [Fri, 10 Nov 2017 05:42:31 +0000] rev 12

Addded patched and renamed rtc_api.c to root of prj


2'nd to publish

2017-11-07, by maxxir [Tue, 07 Nov 2017 17:09:48 +0000] rev 11

2'nd to publish


First release to test RTC on STM32_F103

2017-11-07, by maxxir [Tue, 07 Nov 2017 16:49:43 +0000] rev 10

First release to test RTC on STM32_F103


mbed supports RTC function during RESET & Power ON/OFF. You don't need any modification for mbed library source code. You can just check RTC!!

2017-01-16, by kenjiArai [Mon, 16 Jan 2017 09:38:03 +0000] rev 9

mbed supports RTC function during RESET & Power ON/OFF. You don't need any modification for mbed library source code. You can just check RTC!!


Added F746xx

2016-07-02, by kenjiArai [Sat, 02 Jul 2016 03:08:52 +0000] rev 8

Added F746xx


added L476RG.

2016-05-27, by kenjiArai [Fri, 27 May 2016 20:19:49 +0000] rev 7

added L476RG.


Use mbed-dev lib. (old rev. -> use mbed-src)

2016-01-29, by kenjiArai [Fri, 29 Jan 2016 07:51:04 +0000] rev 6

Use mbed-dev lib. (old rev. -> use mbed-src)


Change SetRTC parameter. Add F344R8 mbed.

2015-05-23, by kenjiArai [Sat, 23 May 2015 22:26:37 +0000] rev 5

Change SetRTC parameter. Add F344R8 mbed.


Bug fix when External Xtal is not avairable. In addtion change checking method for STM32xxx register status

2015-02-19, by kenjiArai [Thu, 19 Feb 2015 02:59:11 +0000] rev 4

Bug fix when External Xtal is not avairable. In addtion change checking method for STM32xxx register status


Only for L152RE, change Deep sleep mode to Standby mode to reduce backup current

2015-02-18, by kenjiArai [Wed, 18 Feb 2015 09:15:37 +0000] rev 3

Only for L152RE, change Deep sleep mode to Standby mode to reduce backup current