-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
boards/sam[r/d]21-xpro: prefer XOSC32K for RTC/RTT (GCLK2) #13306
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I noticed that too.
The RTC/RTT would drift when not using the external oscillator.
I find it a bit weird that we signal the availability of an external oscillator by setting GEN2_ULP32K
to 0
, but that is for another PR.
Yes changing the variable name should be a separate PR. I wanted to PR this too, but was puzzled why it was explicitly set to 1 in the board config. |
I agree that external oscillator should be used rather than the ULP32K by default. |
Do |
08be875
to
e522739
Compare
|
Not the same cpu, but maybe all xpro do? |
I see a big oscillator right on the board when I look at pictures of it. |
samd21-xpro has an external 32khz for sure, dunno about hamilton. |
For the record: |
I think hamilton also got it wrong: #elif CLOCK_USE_XOSC32_DFLL
/* Settings for 32 kHz external oscillator and 48 MHz DFLL */
#define CLOCK_CORECLOCK (48000000U)
#define CLOCK_XOSC32K (32768UL)
#define CLOCK_8MHZ (1)
#define GEN2_ULP32K (1) From the comments I would assume there to be an external oscillator (and setting |
Ok asking the real question: |
I have one, but find it very painful to use |
@Hyungsin you contributed the BOARD, maybe you know if it has an external oscilator? |
The patch applies cleanly to samd21-xpro.patchFrom e522739706f384465756fae4e5188b392a68d1b2 Mon Sep 17 00:00:00 2001
From: Francisco Molina <[email protected]>
Date: Thu, 6 Feb 2020 15:20:08 +0100
Subject: [PATCH] boards/samd21-xpro/include/periph_conf: use XOSC32K
---
boards/samd21-xpro/include/periph_conf.h | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/boards/samd21-xpro/include/periph_conf.h b/boards/samd21-xpro/include/periph_conf.h
index 9bfcb97d656d..4bab39837322 100644
--- a/boards/samd21-xpro/include/periph_conf.h
+++ b/boards/samd21-xpro/include/periph_conf.h
@@ -63,7 +63,16 @@ extern "C" {
*
* @{
*/
-#define CLOCK_USE_PLL (1)
+#define CLOCK_USE_PLL (1)
+#define CLOCK_USE_XOSC32_DFLL (0)
+/*
+ * 0: use XOSC32K (always 32.768kHz) to clock GCLK2
+ * 1: use OSCULP32K factory calibrated (~32.768kHz) to clock GCLK2
+ *
+ * OSCULP32K is factory calibrated to be around 32.768kHz but this values can
+ * be of by a couple of % points, so prefer XOSC32K as default configuration.
+ */
+#define GEN2_ULP32K (0)
#if CLOCK_USE_PLL
/* edit these values to adjust the PLL output frequency */
@@ -75,8 +84,6 @@ extern "C" {
/* Settings for 32 kHz external oscillator and 48 MHz DFLL */
#define CLOCK_CORECLOCK (48000000U)
#define CLOCK_XOSC32K (32768UL)
-#define CLOCK_8MHZ (1)
-#define GEN2_ULP32K (1)
#else
/* edit this value to your needs */
#define CLOCK_DIV (1U) hamilton.patchFrom e522739706f384465756fae4e5188b392a68d1b2 Mon Sep 17 00:00:00 2001
From: Francisco Molina <[email protected]>
Date: Thu, 6 Feb 2020 15:20:08 +0100
Subject: [PATCH] boards/hamilton/include/periph_conf: use XOSC32K
---
boards/hamilton/include/periph_conf.h | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/boards/hamilton/include/periph_conf.h b/boards/hamilton/include/periph_conf.h
index 9bfcb97d656d..4bab39837322 100644
--- a/boards/hamilton/include/periph_conf.h
+++ b/boards/hamilton/include/periph_conf.h
@@ -63,7 +63,16 @@ extern "C" {
*
* @{
*/
-#define CLOCK_USE_PLL (1)
+#define CLOCK_USE_PLL (1)
+#define CLOCK_USE_XOSC32_DFLL (0)
+/*
+ * 0: use XOSC32K (always 32.768kHz) to clock GCLK2
+ * 1: use OSCULP32K factory calibrated (~32.768kHz) to clock GCLK2
+ *
+ * OSCULP32K is factory calibrated to be around 32.768kHz but this values can
+ * be of by a couple of % points, so prefer XOSC32K as default configuration.
+ */
+#define GEN2_ULP32K (0)
#if CLOCK_USE_PLL
/* edit these values to adjust the PLL output frequency */
@@ -77,8 +86,6 @@ extern "C" {
/* Settings for 32 kHz external oscillator and 48 MHz DFLL */
#define CLOCK_CORECLOCK (48000000U)
#define CLOCK_XOSC32K (32768UL)
-#define CLOCK_8MHZ (1)
-#define GEN2_ULP32K (1)
#else
/* edit this value to your needs */
#define CLOCK_DIV (1U) |
e522739
to
429c250
Compare
@benpicco done, does you ACK still apply? |
ACK is still valid. |
No external oscillator on hamilton |
Running from XOSC32K currently uses a long start up time, I'm guessing that is the issue. It should be fixed now. |
@@ -94,6 +108,21 @@ static void clk_init(void) | |||
while (!(SYSCTRL->PCLKSR.reg & SYSCTRL_PCLKSR_OSC8MRDY)) {} | |||
#endif | |||
|
|||
#if CLOCK_USE_XOSC32_DFLL || !GEN2_ULP32K || !GEN3_ULP32K |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a subsequent PR this can be easily replaced by a CLOCK_USE_XOSC32K
or similar
In the datasheet: |
* @note Override this value in your boards periph_conf.h file | ||
* if a different start up time is to be used. | ||
*/ | ||
#define XOSC32_STARTUP_TIME 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not need to be 6 for RTT, but maybe for DFLL it does? I didn't change it because I didn't understand the implications, but at least made it configurable.
Thank you for the cleanup! |
|
@kaspar030 I somehow doubt a change in samd21 code is causing a test failure on nrf52 and esp32. Code works locally, let's ignore those tests. |
All green @benpicco |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good improvement to the accuracy of the RTC/RTT.
Tested on samr21-xpro.
|
@kaspar030 could you elaborate a bit on it ? Is there any link to the CI or something ? |
Looks like startup is taking longer now:
~2.5s to boot |
I was investigating this nightly error: https://ci.riot-os.org/RIOT-OS/RIOT/master/86fcc359947d3647a8d924533ab603177b6f509d/output/run_test/examples/micropython/samr21-xpro:gnu.txt I did a git bisect testing something like |
Could be that the test needs to be syncronized, and as is just fails because it reboots in the middle of the test. |
Contribution description
For
samr21-xpro
,GCLK2
is used to clockRTC
andRTT
. By defaultOSCULP32K
is preferred to clockGCLK2
. On othersam0
boards the actual clock source can be chosen independent ofGCLK
but not forsamr
.OSCULP32K
needs calibration and although:from practical use the clock still needs calibration leading to drifts in
RTC
andRTT
,samr21-xpro
has an external oscillator with a precise value out of the box, so this PR changes the current configuration to prefer that clock asGCLK2
32.768Khz clock source.Testing procedure
Look at the times of each print, this can optionally be verified with an oscilloscope (I did it).
32867Khz
: