I am trying to get the RTC of the stm32h7 to run for a project. Since I didn't get any library working with this RTC like I wanted it to I decided to make it work through processor registers. Currently I have this sketch:
Currently I can set the date and time and read it out properly. My problem starts when I noticed that the rtc was relatively inaccurate and it would loose about 1.5 minutes when running it for an hour or two. Then I noticed it was set up so the selected source for the RTC is LSI. To my understanding the 32.768kHz oscillator on the Portenta H7 (https://content.arduino.cc/assets/Schematic%20PDF_SL-ABX00042.pdf#[{"num"%3A42%2C"gen"%3A0}%2C{"name"%3A"FitR"}%2C0%2C547%2C828%2C0]) should be considered a LSE for the processor. As can be seen in the sketch I tried to manually set the RTCSEL bits to LSE, but when I print out the RCC BDCR register I get: 1000001000000101. Which means, that first off the LSE wasn't selected and instead the LSI was selected again and secondly the LSERDY bit never gets set. Plus the LSE Bypass bit is set for some reason, but I guess that must have something to do with the LSI being selected. Can anyone help me get this woking?
Thanks in advance!
Hey, first off thanks for the reply, but sadly this didn't really help me. I did try to set the bits for the LSE Drive capability to high, but again when I printing out the BDCR register I noticed that it didn't even change the corresponding bits (output was still 1000001000000101). My guess is that this has something to do with the LSE not being selected in the first place, but honestly no idea what is happening there. The calibration thing in the post you linked to is nice and all, but my main problem is not getting the LSE selected in the first place. I don't even know how much the drift of the LSE would be because right now the RTC is only using LSI as its source.
Any other ideas?
If the FixRTC class drive level override didn't work then I guess the portenta H7 is set up differently. I did notice the targets.json mbed file has the portenta lse_bypass set to use an oscillator whereas the GIGA is set to use a crystal. Not sure it's relevant, but it is different.
Hopefully the Arduino team might be able to assist
wait actually.... I did something stupid yesterday because I didn't sleep well enough. The FixRTC class did actually set the LSE Drive bits correctly to HIGH capability. But it still remains, that the Bypass bit is set and the LSI remains selected instead of the LSE.
Tried adding LL_RCC_LSE_DisableBypass(); LL_RCC_SetRTCClockSource(LL_RCC_RTC_CLKSOURCE_LSE); to the FixRTC class to maybe set it through these methods. Intrestingly enough it did disable the bypass and made it possible for LSERDY flag to be set by hardware. Sadly though it didn't select the LSE as the source.
It's really new. Bought it like 2 months ago and say Rev2 on the packet. Anyway, it gets really interesting for me now. I did some more testing and concluded it was the rtc_init() from rtc_api.h function all along. So looking around the stm32h7xx_ll headers I managed to put this together:
Ok, thanks for the help getting the LSE to work, but now I have a weird problem: The clock is now even more wildly inaccurate. What I mean is that in about 10 seconds it counts only 5 seconds. Why is this? Is it a setup issue?
So I commented out my functions for setting and reading the registers and added the rtc_localtime method and it seemed to work fine until I noticed the time drifting again. Then I looked closer and noticed for some reason the rtc_localtime method resets my clocksource back to LSI. This makes absolutely no sense to me. Removing the method and only uncommenting the function I had for reading the time and date registers resulted in the LSE being selected properly, but the time falls behind really far again.
Even more weird I changed the delay from 10 to 1 second to more closely monitor the RTC and when I said it lost about 5 seconds every 10 seconds, I was seemingly lying. In reality it looses 1 second every 4 seconds. Constantly. I look at the serial monitor and every 4th count it repeats the same number again before continuing.
Well that's weird. I already noticed that RTC/LSE has problems, but why is there everything there for people like me who want to use it just to discover it's really quite difficult and doesn't even work properly once you get it "working". Also not even the first revision of this board.
So... is there any hope in me using the RTC on the Portenta H7? Because I am going slowly insane from this.
On that particular board, it feels unlikely. It could be a bad board so my next step would be raising a ticket with Arduino here https://www.arduino.cc/en/contact-us/ linking to this thread. If they can't fix it then I'd go for a replacement. If that also fails then I'd look elsewhere
I was gonna use the RTC for another project and I already have another Portenta H7 board on hand (which was delivered about a week ago actually. Guess I got a bit too excited and didn't wait long enough for testing). I can tell you, uploading the same sketch both with and without rtc_localtime changed nothing about the outcome.
On one hand it would keep the same time for way longer than a second every now and again and on the other hand it would default back to the LSI.
Really just such a disappointment for me personally.
Thanks a lot for your help, I'll have to see if maybe someone else comments on this thread and otherwise leave the RTC idea completely behind me.
I'd still raise it via the contact form to see if they have any suggestions. I'm very happy with the GIGA RTC, it looses a second every three weeks or so.
Happy to help and glad some progress was made that might inform others