F401RE - RTC precision

12 Feb 2015

Hi guys, I'm working on a nucleo board F401RE with online MBED IDE.

I've some problem with the timing, especially with RTC it seems not so precise. I see that the RTC loses some seconds every minute. How is possible to improve the timing accuracy?

Thank you.

19 Feb 2015
16 Feb 2015

Hi, Kenji thank for your relply.

I need to use the board at 84Mhz (as is it now). What I whant to know if is possible to connect an external oscillator (32Khz) only for the Real Time Clock (RTC) to make it more precise.

If is possible I don't want that the entire board runs at 32Khz.

What do you think about it?

Regards

16 Feb 2015

Hi Gian,
You don't worry about it.
F401RE CPU runs 84MHz clock (mbed standard configuration).
In parallel, you can run RTC with external 32.768kHz Xtal if your board equipped X2(Black type Xtal).

17 Feb 2015

Hi Kenji, thank you for your reply.

My nucleo board isn't equipped with 32.768Hz source (X2 connector).

So, I will mount it on X2.

Is there something in the software that I have to setup to select the correct RTC source?

17 Feb 2015

Current mbed library does not support RTC function after reset and power off.
Please try my program if you equip the Xtal and make a back up circuit.
http://developer.mbed.org/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/

18 Feb 2015

Hi Kenjii, I have mounted the Xtal 32Khz on X2.

I'm testing it with your software "RTC (inside STM32x CPU) test program".

My RTC still cotinue to lose 5 seconds every minute.

Any solutions?

18 Feb 2015

If you run my above program, please check a message on your PC.
You can see following screen.
/media/uploads/kenjiArai/external_xtal_0.png
If you have another message "Internal", your mbed has a hardware trouble X2 oscillation.
Please check Xtal and capaciters.
If you still have a trouble, please let us know again.

18 Feb 2015

Test Nucleo RTC Function
Internal Xtal for RTC

Show RTC registers by JH1PJL
 Reg0  =0x00000000, Reg1  =0x00000000
 TR    =0x..000000, DR    =0x..002101, CR    =0x..000000
 ISR   =0x...00007, PRER  =0x..7f00ff, WUTR  =0x....ffff
 CALIBR=0x....0000, ALRMAR=0x00000000, ALRMBR=0x00000000
 WPR   =0x......00, SSR   =0x....0000, SHIFTR=0x....0000
 TSTR  =0x..000000, TSDR  =0x....0000, TSSSR =0x....0000

[Time]  January 01,'00, 00:00:00
Is time correct? If no, hit any key.
                                                  
[Time]  January 01,'66, 00:00:00
Is time correct? If no, hit any key.

As you can see... the message is INTERNAL. I think the capacitor is ok.

The SB45 is still ON. Should I remove it?

18 Feb 2015

Have you changed the mbed-src, rtc_api.c to rtc_api_F4xx.c?
If not, please change the file followed by modify_info_F4xx.h file's procedure.
If modify is already done, please check your board because your PC massage clearly said "Internal Xtal".
This means X2 does NOT start oscillation.
SB45 is okay for 1st step.
"Internal Xtal" issue does not link to backup issue. This is pure X2 oscillation issue.

In addition, please push "RESET" button and check PC screen.
Can you see " Reg0 =0x55aa55aa, Reg1 =0xaa55aa55"?
If not, you doesn't work rtc_api_F4xx.c routine.

18 Feb 2015

Hi Kenjii, I've changed the files as you wrote. Now the terminal says "external"

Test Nucleo RTC Function
External Xtal for RTC

Show RTC registers by JH1PJL
 Reg0  =0x55aa55aa, Reg1  =0xaa55aa55
 TR    =0x..000000, DR    =0x..002101, CR    =0x..000000
 ISR   =0x...00017, PRER  =0x..7f0137, WUTR  =0x....ffff
 CALIBR=0x....0000, ALRMAR=0x00000000, ALRMBR=0x00000000
 WPR   =0x......00, SSR   =0x....0000, SHIFTR=0x....0000
 TSTR  =0x..000000, TSDR  =0x....0000, TSSSR =0x....0000

[Time]  January 01,'00, 00:00:00
Is time correct? If no, hit any key.
15 2 18 14 42 0

Set time into RTC
 e.g. >15 2 7 10 11 12 -> Feb. 7th, '15, 10:11:12
 If time is fine, just hit enter

But I think that the RTC doesn't start, because the while condition

        while (seconds == time(NULL)){

is false, so the firmware run only one time.

19 Feb 2015

Hi Gain,
Thanks for your big hint!!
I re-review my code "SetRTC Lib" and found several problem in my code.
I have updated test program as follow.
/users/kenjiArai/code/Nucleo_RTC_battery_bkup_pwr_off_okay/rev/a9cebfe4715f

I believe that you will NOT satisfy new program and you will NOT success the External Xtal oscillation.
There are two kinds of problem in the past.

1) Your F401RE mbed board. ->External Xtal circuit has a trouble. From your previous report, your X2 cannot oscillate yet.
You need to re-check soldering condition and others. Worst case, you need to change C31 & C32 cap.

2) My mistakes (made a bugs)
a)Miss judge LSE Xtal oscillation (bug in rtc_external_osc_init(), SetRTC.cpp)
Once External Xtal is available (oscillated), previous program does NOT check detail condition after Reset and/or Power on/off even if External Xtal cannot oscillate at the time.
b)NOT show current time when X2 does NOT oscillate (bug in main())

19 Feb 2015

Hi Kenji, thank you for all the help!

I will check C31 and C32 capacitor and, I will try you new code and let you know how it works!

19 Feb 2015

Good morning Kenji, something gone wrong today.

I have only updated your software and now terminal says "Internal Xtal for RTC"

I'm a little bit confused about it.

19 Feb 2015

As I mentioned before follows.
"I believe that you will NOT satisfy new program and you will NOT success the External Xtal oscillation."
X2 can oscillate sometime and not always!!
Please check HW and modify C31 & C32.
If you have 5 to 8pF cap., please also try that value.
I also have F401RE board new and old type.
In the beginning, I also had a trouble C31 & C32 for old type and my final value are C31=10pF, C32=8pF.
I don't have any background information for this value and it totally depends on X2 supplier's specification.
In addition, please set DEBUG mode, Line 21 in SetRTC.cpp and check timeout with RESET button again again.

19 Feb 2015

Ok, in this moment C31 & C32 is 12pF.

So, I will change it to something between 5 and 8pF and make a test.

I will let you know.

(I did not think it was so hard to make RTC works)

21 Feb 2015

Hi Kenji, finally seems that RTC works.

I've changed C31 & C32 to 4.3pF and I've mounted R34 & R36 (0 Ohm) resistor.

Now your code works.

My RTC loses about 3 seconds in over 10 hours... I think is enought.

21 Feb 2015

Good Job!!