From f6139ae346ffbfdd4adcbd7322890f746de8464c Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 18 Mar 2020 23:48:08 +0100 Subject: [PATCH] cpu/samd5x: work around errata when (re-)initializing DFLL When a previously disabled DFLL gets enabled again, the frequency will be incorrect. Follow the procedure outlined in the errata sheet, section 2.8.3 to work around the issue. This fixes wake from standby. --- cpu/samd5x/cpu.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cpu/samd5x/cpu.c b/cpu/samd5x/cpu.c index 830c0f66e2..a1cf045119 100644 --- a/cpu/samd5x/cpu.c +++ b/cpu/samd5x/cpu.c @@ -64,9 +64,14 @@ static void dfll_init(void) #endif ; - OSCCTRL->DFLLCTRLB.reg = reg; - OSCCTRL->DFLLCTRLA.reg = OSCCTRL_DFLLCTRLA_ENABLE; + /* workaround for Errata 2.8.3 DFLLVAL.FINE Value When DFLL48M Re-enabled */ + OSCCTRL->DFLLMUL.reg = 0; /* Write new DFLLMULL configuration */ + OSCCTRL->DFLLCTRLB.reg = 0; /* Select Open loop configuration */ + OSCCTRL->DFLLCTRLA.bit.ENABLE = 1; /* Enable DFLL */ + OSCCTRL->DFLLVAL.reg = OSCCTRL->DFLLVAL.reg; /* Reload DFLLVAL register */ + OSCCTRL->DFLLCTRLB.reg = reg; /* Write final DFLL configuration */ + OSCCTRL->DFLLCTRLA.reg = OSCCTRL_DFLLCTRLA_ENABLE; while (!OSCCTRL->STATUS.bit.DFLLRDY) {} } @@ -152,8 +157,12 @@ void cpu_pm_cb_enter(int deep) void cpu_pm_cb_leave(int deep) { - (void) deep; /* will be called after wake-up */ + + if (deep) { + /* DFLL needs to be re-initialized to work around errata 2.8.3 */ + dfll_init(); + } } /**