2016-09-08 08:52 AM
Hi,
I have a problem where I'm trying to detect the presence of the low speed external oscillator, and to use it if it is installed. On bootup, it does the following: * Turn LSI on (it always defaults to off) * If RTC is set up already then great. Job done. * If not, set up the RTC with the LSI, but turn the LSE on * Around 1 sec later, in SysTick, check if the LSE is working * If it isn't, turn it off * If it is, reset backup domain, switch over to LSE and disable LSIWhen I do this on STM32F1 it works great. On the STM32F4 it works fine for just the LSI, but when the LSE is installed it's left in a state where the registers say:* LSI is off* LSE in on, and working* LSE is set as the RTC clock source* RTC is enabledHowever the RTC itself is no longer working.Does anyone have any ideas what the problem could be? When I reset the backup domain (which I have to in order to switch the RTC over) could I have missed out some configuration?The odd thing is that if I reset the board after this, everything comes up fine - so it's as if I got the RTC into some strange state.RTC Initialisation code:https://github.com/espruino/Espruino/blob/6ec6946bdbb7e35d19037615d421eda5d19a44f4/targets/stm32/jshardware.c&sharpL1111Code that runs after ~1 sec:https://github.com/espruino/Espruino/blob/6ec6946bdbb7e35d19037615d421eda5d19a44f4/targets/stm32/jshardware.c&sharpL736And yes, one answer would be just to pause the whole MCU while I waited for the LSE - but I need a fast startup time and to be able to use the RTC during that time (so I have to run it off the LSI until the LSE has started). #rtc #stm322016-09-08 10:03 AM
> * RTC is enabled
> > However the RTC itself is no longer working. Post content of relevant registers at that point. JW2016-09-08 10:49 AM
Hi Gordon Williams,
Since the code that you provided managed RTC for more than one device, it is not so obvious to identify the root cause. Try to clear and keep only RTC part in a new main. Meanwhile, after a quick check , you may check the following points: * Assynchronous and Synchronous predivs setting for the STM32F4 case * Why you are setting alarm with STM32F1 and WUT in case of STM32F4 ? Is RTC not supposed to behave the same ? -Hannibal-2016-09-08 11:10 AM
>
Post content of relevant registers at that point.
Which ones would you like? I posted the specific parts of registers I thought were relevant already but I can post the contents of any registers you'd like.> Since the code that you provided managed RTC for more than one device, it is not so obvious to identify the root cause. Try to clear and keep only RTC part in a new main.
It's just anything that is ifdef'd STM32F4 and not ifdef'd STM32F1. I know it's a little frustrating but it might also help knowing that it works on F1 but not F4 - and you'd lose that if I deleted the ifdefs for you.> Assynchronous and Synchronous predivs setting for the STM32F4 caseDo these get cleared when the backup register flags are set? Also, I'd have thought they would only be able to change the speed of the RTC, not stop it completely which appears to be what's happening?> Why you are setting alarm with STM32F1 and WUT in case of STM32F4 ? Is RTC not supposed to behave the same ?I didn't think the F1 had a wake up timer? I can't use an alarm on the F4 because I want higher accuracy than 1 second on F4 (it doesn't seem possible on F1).Even so, that shouldn't be relevant here as it's broken long before that point. It's literally just the two areas I pointed at.Is there a way to set the RTC prescaler and clock source without resetting everything first? That could make life a lot easier.2016-09-08 11:28 AM
> >
Post content of relevant registers at that point.
>
> Which ones would you like? > I posted the specific parts of registers I thought were relevant already Where? I mean, contents of registers read out at the moment when you judged RTC inoperative. > but I can post the contents of any registers you'd like. *I* don't need any. Post what *you* deem relevant - post all of RTC and RTC- and LSE- specific from RCC and PWR.JW
2016-09-09 01:53 AM
> Where?
I posted LSE state, clock selection, etc - I didn't post the raw register contents though.> Post what *you* deem relevantIf I knew what was relevant I'd be a lot closer to having the answer already :)I just read all the RTC/RCC/PWR registers when it was working (after reset) and when it was broken (after power on), and diffed them.The only differences were:2016-09-09 02:15 AM
So, problem solved?
> Looks like RTC_WaitForSynchro after RTC_SetDate seems to be quite vital Surely something well-described in the ''library's'' documentation...? JW2016-09-09 02:29 AM
Yes, problem solved.