cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 low RTC precision

Posted on March 05, 2018 at 07:57

Hello there,

I am using an STM32L4 family MCU. In an application, the RTC peripheral is utilized and clocked from an external crystal:

0690X00000609xVQAQ.png

0690X00000609vUQAQ.png

The problem I have noticed just now is that with time, the RTC timer looses sync. It is not easy to notice in short periods of time, but after leaving the application to log time for entire weekend, I noticed that the RTC timer is over 20 minutes later after my PC timer (they were both synced before the weekend).

What could be the cause of this problem? Its hard to believe for me that the RTC timer is simply this low precision, as I am using an external crystal. I would appreciate all help.

#precision #stm32l4 #rtc

Note: this post was migrated and contained many threaded conversations, some content may be missing.
71 REPLIES 71
Posted on March 09, 2018 at 21:11

the issue there is related to insufficient drive, to my undrestanding, on F1 chips -> i'm not aware of F2/F4 chips having similar issues.

not sure if that applies here as the oscillator is obviously working, unless the clock is switched to LSE -> if so, the error of 6000ppm wouldn't sufficient.

the whole thing is fairly easy to debug.

Posted on March 09, 2018 at 21:48

Just to sum things up:

  1. I do not have a better scope at hand. I know this one is poor. So I cannot really measure the frequency any more precisely.
  2. I understand I need to check the code generated by CubeMX (since I am not setting it by hand), either the prescallers and periods are alright.
  3. My crystal and its capacitors choice is wrong, I need to replace them anyway. I should start with this.

Am I right or did I not get something?

Posted on March 10, 2018 at 02:17

Set the scope to measure 10 cycles, you can get a better measurement that way.

Yes, pull the crystall and caps off the board.

clean footprints with Metho, then flux and replace with new high quality matched parts. (xtal and caps)

you should be able to get to 100ppm easily.

then bake for a few hours and use conformal coating to stabilize the crystal frequency.

if you would like to send the cube file I can have a look. not sure there is anything to see there...

but just so you know, 32768.1 is bad enough, 32786.885 is horrible.

Posted on March 10, 2018 at 09:45

Thanks for answer,

I will start with replacing the parts and trying to get better scope, this one has limited functionality.

Just a personal note: I wish my more critical problems described on those forums escalated this far.

Posted on March 10, 2018 at 23:59

Like they have been saying, you may want a frequency counter, much more accurate for this measurement.

gbm
Lead III
Posted on March 11, 2018 at 10:31

I tried to read all the answers in this topic and I cannot find an answer similar to my experiences - excuse me if overlooked it. Here are my suggestions:

The L4 LSE circuit is EXTREMELY sensitive to interferences. Any change of state on the tracks on the PCB going close to the oscillator (even if no current flows through them) results in LSE skipping several pulses and getting out of sync. What you observe is not a surprise, it's how it typically behaves.

To eliminate the problem, make sure that:

- the connections between MCU and crystal ale short,

- there are ABSOLUTELY NO SIGNAL TRACES in top layer under the crystal and in the next layer under the traces connecting the crystal to MCU,

- if there are such traces - use a crystal with a metal can and ground its case - it may help a little on your prototype board,

- there is a solid ground plane under the crystal and its traces to the MCU,

- the capacitors are between the MCU and the crystal or at the crystal pins, not outside of the crystal with long connecting traces,

- the MCU pins close to the LSE pins are not used for any waveform output (including MCO) - better don't use them at all.

Fiddling with LSEDRV setting may help.

Also note that if your LSE circuit is not perfect and you use it for synchronizing the main clock (a very useful option in L4 for eliminating the HSE crystal), you will encounter UART and USB data errors (like I did).

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Posted on March 11, 2018 at 10:47

Thank you for answer,

To answer your questions, here is screenshot of how the crystal is routed:

0690X0000060A5aQAE.png

Its the Y2 crystal.

I would not say that your guidelines were followed. I paid a lot more attention to the HSE placement to be fair, as I thought at this frequency (32 kHz) there are not hard constraints when it comes to placement. This is a 2 layer board so the is no solid GND plane underneath the crystal. Do you really think that this could make the difference?

Posted on March 11, 2018 at 13:29

If

Mazur.Grzegorz

‌ is correct, you have noise injection from the ground fills, from the switchers.

I would remove the ground fill from the crystal circuit area totally and off C16, C17, try to move underside tracks away if possible.

Run a 15thou trace from C17,C16(Gnd), to pin 10 Vss, before it hits C25, then connecting to the remaining ground fill/track.

This will mostly block any switcher noise you have propagating along Vss,.along your ground fills.

Posted on March 11, 2018 at 15:05

Your layout is not perfect but not bad. I would try to move away the tracks crossing LSE tracks and slightly move the capacitors. I would suggest to try another oscillator, 'straw' thin can 'watch' type and ground its case. The black plastic one you use is the worst one for L4 (I did the same, so I know) . Try 6p8 capacitors and LSEDRV options. The LSE tracks should ideally go through the LCE capacitors to the oscillator.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Posted on March 11, 2018 at 20:27

I will try another oscillator in the next revision, thanks. About the caps in the way of routes- I find it hard to measure either this really makes sense at this frequencies. Also, its not good reflow oven soldering wise.