Page 1 of 1

[STM32L476DISCO] RTC not ticking

Posted: Tue Sep 26, 2017 12:37 pm
by roland_vs
Dear all,

Anyone experienced the fact that the RTC is not running?

import pyb
pyb.RTC().datetime() should change every time you issue this command.
Also setting the clock takes about a second or so before the prompt returns, but no changes to the registers at all.

The default time is stuck at (2000,1,1,0,0,0,0,0,0), so the default that is setup in the code rtc.c is not copied to the RTC.

Testing the same code (latest mpy) on the pyb10 and other F4 versions works fine, however the L4 versions do not.

Before diving into the possible problem, does anyone had the same problem and already fixed it?



Re: [STM32L476DISCO] RTC not ticking

Posted: Wed Sep 27, 2017 7:13 am
by pythoncoder
I have seen that on the Pyboard when I've inadvertently stopped the 32KHz oscillator. This can occur if you forget that it's still running when the board is powered down but fitted with a backup cell - touching the crystal or its capacitors can stop the oscillator.

Re: [STM32L476DISCO] RTC not ticking

Posted: Wed Sep 27, 2017 9:52 am
by roland_vs
@pythoncoder Dear Peter,

Indeed I noticed when I put my finger on the capacitors next to the 32kHz Oscillator REPL via the USB doesn't respond, and removing the finger everything works again.

I tested the L476 port on the original STM32L476DISCO (reference) and two boards of my own making. They all have the same problem: RTC not running. All of the boards I have with the F4 series (405, 407, 439) work OK. That may lead to the conclusion that it is a problem with the L476, but it would be nice if there is anyone with an L476 based board to verify it...

Also I assume that writing a set of new values like (2017,9,27,11,12,3,0,0) should at least copy the values to the RTC registers even when the clock is not ticking...

Re: [STM32L476DISCO] RTC not ticking

Posted: Tue Nov 28, 2017 3:03 pm
by roland_vs

I have updated the `mpconfigboard.h` of my own board variant and the `STM32L476DISCO` by adding the external oscillator to be enabled:


The RTC will run now. This does not explain why it's not running using `lsi` or `msi` mode, but at least my hardware is ticking....

Re: [STM32L476DISCO] RTC not ticking

Posted: Sun Dec 10, 2017 2:05 pm
by badi
The #define fix does not work on my board.

However after a longer debug session I discovered, that calling the init() from MicroPython on the RTC starts the clock - which is not needed on the F4 - even without the #define in the header file.

If you look on the clock-tree of the L4 (eg. CubeMx or reference manual) you will notice, that only the LSI or the LSE can feed the clock for the RTC. With the #define i assume that the RTC runs on the more precise external crystal.

I do not know yet, why this init function exists a when it is or should be called.


Re: [STM32L476DISCO] RTC not ticking

Posted: Fri Jan 25, 2019 8:18 pm
by Niallp
Many thanks for pointing out the init() function and that it needs to be called explicitly ... I couldn't figure out why the clock wasn't running on my board (based on the Nucleo-L476RG port) unless I had already run some other code (using CubeMX) that had initialized access to the RTC backup registers.

Need to dig deeper to understand why the L4 and Fx ports operated differently, haven't found it in rtc.c yet.