Nucleo series RTC control under Power On/Off and Reset condition
.
updated on January 16th, 2017
You do NOT need any modification for mbed source code!! Just use it and works fine.
[1st try with no hardware modification]
You DON'T need a battery back up circuit as 1st trial.
RESET -> Please run it and push reset button to see what's happened.
Standby -> Please run it and push user button to enter standby mode (deep sleep) then push reset button.
Import programNucleo_RTC_battery_bkup_pwr_off_okay
In the past, you need modify rtc_api.c in mbed-dev source code. From this revision, you can just use RTC function all of conditions (Normal, Reset, Stand-by, Power OFF).
[2nd try with additional hardware circuit]
Before making a back-up circuit, you need to identify your own Nucleo mbed board VBAT control logic.
Please refer following two different logic.
If you have Nucleo-F401RE,-F411RE type of VBAT circuit, you can just make following simple back-up circuit.
If you have Nucleo-L152 type of mbed, you need additional big effort becauseL152 does NOT have VBAT pin.
If you would like to set up those back-up circuit, please refer bottom of this page.
[Tested board]
Reset | Stanby | Power off and restart | |
Nucleo-F401RE | ok | ok | ok (Back-up Circuit) |
Nucleo-F411RE | ok | ok | ok (Back-up Circuit) |
Nucleo-F446RE | ok | ok | ok (Back-up Circuit) |
Nucleo-F334R8 | ok | ok | ok (Back-up Circuit) |
Nucleo-L476RG | ok | ok | ok (Back-up Circuit) |
Nucleo-L152RE | ok | ok | no check (Need additional hardware) |
Nucleo-L073RZ | ok | ok | no check (Need additional hardware) |
Nucleo-L053R8 | ok | ok | no check (Need additional hardware) |
Followings are old information
updated on July 2nd, 2016
Added F746xx.
updated on May 28th, 2016
Added L476RG mbed.
Changed SetRTC and rtc_api.c for F401RE & F411RE, F334R8 based on latest mbed-dev revision (141).
updated on May 24th, 2015
Changed SetRTC parameter.
Added F334R8 mbed.
Backup circuit is same as F401RE & F411RE (simple solution. Please refer [Hardware Configuration] Case F401RE or/and F411RE)
updated on Feb. 22nd, 2015
Added new back-up circuit only for L152RE.
updated on Feb. 18th, 2015
Change Deep Sleep Mode to Standby Mode to reduce backup current (Only for Nucleo L152RE).
updated on Feb. 17th, 2015
Added interrupt driven power off sequence for L512RE mbed
updated on Feb. 14th, 2015
Added L512RE mbed solution
[Current Nucleo RTC problem]
1) External Xtal (32.768kHz) / LSE clock does not start due to HW & SW current setting (Not always but many times).
2) After starting a RTC function in the user program, RTC cannot continue the count when power off or/and reset even HW has a 3V battery back-up circuit.
[Available functions]
Please try this code without any additional circuit!
You DON'T need a battery back up circuit and LCD as 1st trial. Please run it and push reset button to see what's happened.
Import programNucleo_RTC_battery_bkup_pwr_off_okay
In the past, you need modify rtc_api.c in mbed-dev source code. From this revision, you can just use RTC function all of conditions (Normal, Reset, Stand-by, Power OFF).
1) Not initialize RTC register configuration if back-up registers have some specific data (judge/battery back-up circuit works well).
2) Wait LSE (External Xtal) start up time (much longer than mbed original start up time) and use External 32.768kHz OSC if it's available.
3) Can set the present time and date from PC via USB VCOM line as first time initialization.
4) Show RTC register’s contents if you want.
5) Enter “Deep Sleep mode” if you want.
In case L152RE, this is mandatory before power off. In addition, you can power off anytime if PB5 sets +5V voltage drop detection circuit.
IMPORTANT
If you run the program without any modification, you can see following screen in your PC.
If your screen shows "Internal Xtal", you may have a trouble for external Xtal oscillation!!.
[Software Configuration]
Before compile the program, you need to modify rtc_api.c file in the mbed-dev library.
Case F401RE or/and F411RE
(1) Update mbed-dev library if you want
(2) File rtc_api_F4xx.c copy to directory /mbed-dev/targets/hal/TARGET_STM/TARGET_STM32F4/
(3) Delete rtc_api.c in the same directory
(4) Edit rtc_api_F4xx.c
a)Delete 1st line
b)Delete last line
Case L152RE
(1) Update mbed-src library if you want
(2) File rtc_api_L152.c copy to directory /mbed-dev/targets/hal/TARGET_STM/TARGET_STM32L1/
(3) Delete rtc_api.c in the same directory
(4) Edit rtc_api_L152.c
a)Delete 1st line
b)Delete last line
Case F334R8 & L476
Same as F401&F411 case.
If you did it successfully the above modification, you can see following warning message after compile (Condition: Compile All).
Waring directive: "You modified mbed-dev rtc_api.c for SetRTC functions""#waring "You modified mbed-dev rtc_api.c for SetRTC functions""
Please confirm it.
[Hardware Configuration]
Case F401RE or/and F411RE (+ F334R8 & L476)
Please refer following picture (Circuit and layout)
Case L152RE
Please refer below "Additional information only for L152" part.
You DON'T need any additional modification for L152RE mbed board(don't remove SB45!!).
[Detail explanation of functions]
1) Forget everything!!
Current mbed library initialize RTC related registers every power on reset and other reset conditions.
rtc_api.c
void rtc_init(void){ // SKIP RtcHandle.Instance = RTC; // Enable Power clock __PWR_CLK_ENABLE(); // Enable access to Backup domain HAL_PWR_EnableBkUpAccess(); // !!!!!!!!! This is a problem !!!!!!!!!!! // Reset Backup domain __HAL_RCC_BACKUPRESET_FORCE(); __HAL_RCC_BACKUPRESET_RELEASE(); // SKIP }
After running user program, it's too late to recover RTC time count and back-up data.
I use “mbed-dev” library and modify the file, "rtc_api.c" to prevent this issue.
2) How to recognize the back up is success or not?
Case F401RE or/and F411RE (F334 & L476)
VBAT power line connected to not only RTC but also Backup registers.
I use two(or three) 32bit registers to keep special value and check the value in the initialize routine.
If specific value remains, initialize routine skips most of the part and continue RTC function.
rtc_api.c
void rtc_init(void){ // SKIP // Check backup condition if (Check_Rtc_backup_reg()){// If back up data are remain, we can skip RTC initialize return; } // SKIP /* Write backup data into the backup RAM */ RTC_WriteBackupRegister( RTC_BKP_DR0, RTC_DAT0 ); RTC_WriteBackupRegister( RTC_BKP_DR1, RTC_DAT1 ); // SKIP }
Case L152RE
L152 does NOT have VBAT pin.
It's easy to set RTC function for F401 & F411 CPU but not so easy for ST Nucleo L152RE mbed board due to back up HW
configuration is different.
You can see following diagram in the manual.
CAUTION!
We need to set CPU sleep condition and keep alive CPU VDD line.
This means we should check a condition and execute sleep command if you want to go to power off the board.
3) LSE(External 32.768kHz Xtal) oscillation is too slow to start.
The mbed library only wait 600msec (Changed more longer) then give it up to use LSE then use LSI even the external Xtal is on the Nucleo mbed board.
Please refer this page to understand this issue.
/users/kenjiArai/notebook/nucleo-series-clock-structure-and-xtal-oscillation/
[Extend other Nucleo series]
I briefly check STM32 series documentations and summarize as follows.
No. | Board name | Available VBAT Pin | Comment | |
---|---|---|---|---|
1) | L053R8 | No | ||
2) | L152RE | No | works my environment | |
3) | F030R8 | No | ||
4) | F072RB | Yes | ? | |
5) | F091RC | Yes | ? | |
6) | F103RB | Yes | ? | |
7) | F302R8 | Yes | ? | |
8) | F334R8 | Yes | Works fine | May 24th,'15 |
9) | F401RE | Yes | Works fine | |
10) | F411RE | Yes | Works fine | |
11) | L476RG | Yes | Works fine | May 28th,'16 |
[Additional information only for L152]
CAUTION!
An interrupt driven power off sequence needs additional hardware circuit because the function use PB5(or PB6) COMP input to check +5V live voltage drop detection.
If you don't have those circuit, please comment out following part.
SetRTC.h
//#define USE_IRQ_FOR_RTC_BKUP // Use interrupt for enter RTC backup mode
backup current = 100uA (Standby mode(latest))
backup current = 280uA (Old revision Deep Sleep mode)
NEW BACKUP CIRCUIT FOR L152RE mbed
Use Renesas PS7200K-1A, FET Optocouple.
7 comments on Nucleo series RTC control under Power On/Off and Reset condition:
Please log in to post comments.
Thanks for all the info. I'm currently working on a project using the l152re that requires the rtc. I'll try your program once the l152 is supported.