-
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
cpu/samd5x: enable FDPLL1 at 200MHz #19581
Conversation
cpu/samd5x/cpu.c
Outdated
return; | ||
} | ||
|
||
/* We source the DPLL from 32kHz GCLK1 */ | ||
const uint32_t LDR = ((f_cpu << 5) / 32768); | ||
const uint32_t LDR = (f_cpu / 32768); |
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.
Alternatively you could have used
const uint32_t LDR = (f_cpu / 32768); | |
const uint32_t LDR = (f_cpu >> 10); /* LDR = ((f_cpu << 5) / 32768) */ |
Should be the same as ((f_cpu << 5) / 32768)
. This might me more reproducible together with the former code for DPLLRATIO
.
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.
I'll give it a try.
98c1e4b
to
81a3ed6
Compare
@gschorcht I've applied your changes and squashed. |
Hm, are you sure about that? With |
cpu/samd5x/cpu.c
Outdated
@@ -354,7 +353,8 @@ void cpu_init(void) | |||
|
|||
xosc_init(0); | |||
xosc_init(1); | |||
fdpll0_init(CLOCK_CORECLOCK * DPLL_DIV); | |||
fdpll_init(0, CLOCK_CORECLOCK * DPLL_DIV); | |||
fdpll_init(1, MHZ(200)); |
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.
Current consumption is back to normal when I remove this line.
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.
Strange, the ONDEMAND bit is set and since nobody is connected yet to the associated GCLK it shouldn't impact the overall consumption...
I'll investigate.
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.
Okay, I've found the reason why. ONDEMAND bit is "enable-protected".
I'll provide a fix later.
This also mean that the FDPLL0 is not running with ONDEMAND set which is a bug.
I don't have a scope at hand, but I can confirm that it seems to work. Independent on that the manual seems to be wrong regarding the description of the calculation of DIV as discussed with @dylad already, I get now the following SDCLK frequencies:
All speeds should be exactly the double. Some debug output from
According to the manual, |
81a3ed6
to
8c76e71
Compare
@benpicco I've slightly change the |
@benpicco Can you confirm that there is no change in power consumption if FDPLL1 isn't used? |
Now it hangs on init: 0x00000d78 in fdpll_init (flags=128 '\200', f_cpu=200000000, idx=1 '\001') at /home/benpicco/dev/RIOT/cpu/samd5x/cpu.c:218
218 while (!(OSCCTRL->Dpll[idx].DPLLSTATUS.bit.CLKRDY &&
OSCCTRL->Dpll[idx].DPLLSTATUS.bit.LOCK)) {} It works when I remove the --- a/cpu/samd5x/cpu.c
+++ b/cpu/samd5x/cpu.c
@@ -354,7 +354,7 @@ void cpu_init(void)
xosc_init(0);
xosc_init(1);
fdpll_init(0, CLOCK_CORECLOCK * DPLL_DIV, 0);
- fdpll_init(1, MHZ(200), OSCCTRL_DPLLCTRLA_ONDEMAND);
+ fdpll_init(1, MHZ(200), 0);
/* select the source of the main clock */
if (USE_DPLL) { |
I'll have my board back tomorrow. I'll give it a try. |
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
These functions can be used to set both FDPLL0 and FDPLL1 by using an extra argument 'idx' (index) and allow to set the ONDEMAND bit using the 'flags' argument Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
Signed-off-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
8c76e71
to
6607ed1
Compare
FDPLL0 no more blocks with ONDEMAND and power consumption is back to normal. |
bors merge |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
Thanks for the review & merge ! |
Contribution description
This PR allows to use the second FDPLL (the first one is used to generated the 120MHz frequency used by the core and some peripherals). The second FDPLL is setup to run at 200MHz which is the maximum allowed by this MCU.
In fact, I reused the existing function which setup FDPLL0 so it can be used in a generic way for both PLL (since they are the same IP).
I change the way the computation offset (left shift by 5) is done because 200MHz << 5 wouldn't fit inside an
uint32_t
and I wanted to avoid using anuint64_t
hereTwo additional commits are present for a small cleanup and a fix.
This is currently unused in our codebase, so it shouldn't impact this platform too much as the
ONDEMAND
bit is set. the FDPLL will not be running out of the box. But @gschorcht might need it pretty soon.Testing procedure
This PR can be tested on a
same54-xpro
and an oscilloscope using the following the patch:It will output both FDPLLs to PB14 and PB10. Their frequency can then be measured using an oscilloscope.
Issues/PRs references
None.