Seek assist-Arduino GIGA R1 (STM32H7) RTC usage
Posted: Fri Jan 12, 2024 10:30 pm
Hello -
I have an Arduino GIGA R1 that is chipped with an STM32H747 (RM0399 linked here), and use the Arduino IDE to work with the board. There is an in-chip RTC, complemented by a 32.768kHz crystal across PC14 and PC15, for the LSE clock source. However, I believe the RTC is defaulting to the LSI source, and hence RTC is wildly inaccurate. My sole previous experience has been with AVRs, so when I see "RTC" and "crystal" I say "Let's make a clock!" With the GIGA R1 I am admittedly out of my depth in STM32 waters.
I would like to utilize the external crystal mounted to this board and run the LSE, hopefully to tighten up the RTC error, and I seek others assistance in doing so.
It took me a few hours to figure out how to do just this...
It was the -> that I didn't get, new syntax learning curve suppose.
Anyway, Serial gave this...
Deciphering this I find RTC is enabled, ok. LSE is chosen as clock source and enabled, however clock security set a flag. Ugh. Well, this little demonstration prolly doesn't mean much as it is just a snippet of code.
However, when I wrap that bit into the RTC example sketch...
...I receive this in Serial.
Polling that register shows me that now the LSI is selected, LSE is still not ready (bit:1 = 0), and the persistent bit:6 flag indicating failure detected on external crystal. Even more vexing is that crashes my board, so the time indicated in Serial is actually including the accrued error of the LSI over the past several weeks.
So, I seek your folks' assistance in helping me to understand what it is going on here.
As an aside, I am a new member, and this is my first post. I run with the Arduino IDE on a Win11 machine and feel woefully inadequate at addressing this issue. If there is anything I can do to fill in gaps here in my post that may help you understand what I am experiencing please let me know.
Thank you for taking an interest in this topic.
Mark
I have an Arduino GIGA R1 that is chipped with an STM32H747 (RM0399 linked here), and use the Arduino IDE to work with the board. There is an in-chip RTC, complemented by a 32.768kHz crystal across PC14 and PC15, for the LSE clock source. However, I believe the RTC is defaulting to the LSI source, and hence RTC is wildly inaccurate. My sole previous experience has been with AVRs, so when I see "RTC" and "crystal" I say "Let's make a clock!" With the GIGA R1 I am admittedly out of my depth in STM32 waters.
I would like to utilize the external crystal mounted to this board and run the LSE, hopefully to tighten up the RTC error, and I seek others assistance in doing so.
It took me a few hours to figure out how to do just this...
Code: Select all
void setup() {
Serial.begin(9600);
delay(4000);
Serial.println("test");
delay(1000);
Serial.println(RCC->BDCR, BIN);
}
void loop() {}
Anyway, Serial gave this...
Code: Select all
12:05:19.830 -> test
12:05:20.874 -> 1000000101100001
However, when I wrap that bit into the RTC example sketch...
Code: Select all
/*
From: https://docs.arduino.cc/tutorials/giga-r1-wifi/cheat-sheet#rtc
Accessed: 12 Jan 2024
*/
#include "mbed.h"
#include <mbed_mktime.h>
constexpr unsigned long printInterval{ 1000 };
unsigned long printNow{};
uint64_t last_millis = 0;
void setup() {
Serial.begin(9600);
//RTCset();
}
void loop() {
if (millis() > printNow) {
Serial.print("System Clock: ");
Serial.println(getLocaltime());
printNow = millis() + printInterval;
}
if (millis() - last_millis > 5000) {
last_millis = millis();
Serial.println(RCC->BDCR, BIN);
}
}
void RTCset() // Set cpu RTC
{
tm t;
t.tm_sec = (0); // 0-59
t.tm_min = (16); // 0-59
t.tm_hour = (10); // 0-23
t.tm_mday = (12); // 1-31
t.tm_mon = (0); // 0-11 "0" = Jan, -1
t.tm_year = ((24) + 100); // year since 1900, current year + 100 + 1900 = correct year
set_time(mktime(&t)); // set RTC clock
}
String getLocaltime() {
char buffer[32];
tm t;
_rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT);
strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
return String(buffer);
}
Code: Select all
12:02:20.436 -> System Clock: 2023-01-11 19:52:21
12:02:21.419 -> System Clock: 2023-01-11 19:52:22
12:02:22.418 -> System Clock: 2023-01-11 19:52:23
12:02:23.016 -> 1000001001100001
12:02:23.433 -> System Clock: 2023-01-11 19:52:24
12:02:24.449 -> System Clock: 2023-01-11 19:52:25
12:02:25.433 -> System Clock: 2023-01-11 19:52:26
Code: Select all
RTCSet();
So, I seek your folks' assistance in helping me to understand what it is going on here.
As an aside, I am a new member, and this is my first post. I run with the Arduino IDE on a Win11 machine and feel woefully inadequate at addressing this issue. If there is anything I can do to fill in gaps here in my post that may help you understand what I am experiencing please let me know.
Thank you for taking an interest in this topic.
Mark