From b795cb7ef4634bc782d557846b69da66bf36804f Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 8 Aug 2022 05:42:03 +0100 Subject: [PATCH] samd: Added an errata workaround for the SAMD11 DFLL48M which can have issues if left unrequested before configuration. --- src/target/samd.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/target/samd.c b/src/target/samd.c index c9659e3..84a2531 100644 --- a/src/target/samd.c +++ b/src/target/samd.c @@ -298,6 +298,22 @@ static void samd20_revB_halt_resume(target *t, bool step) target_mem_write32(t, SAMD_DSU_CTRLSTAT, SAMD_STATUSA_CRSTEXT); } +/* + * Release the target from extended reset before running the normal cortexm_attach routine. + * This prevents tripping up over errata ref 9905 + * + * Only required for SAM D11 silicon. + */ +static bool samd11_attach(target *t) +{ + /* Exit extended reset */ + if (target_mem_read32(t, SAMD_DSU_CTRLSTAT) & SAMD_STATUSA_CRSTEXT) + /* Write bit to clear from extended reset */ + target_mem_write32(t, SAMD_DSU_CTRLSTAT, SAMD_STATUSA_CRSTEXT); + + return cortexm_attach(t); +} + /* * Overload the default cortexm attach for when the samd is protected. * @@ -505,6 +521,12 @@ bool samd_probe(target *t) */ t->detach = samd20_revB_detach; t->halt_resume = samd20_revB_halt_resume; + } else if (samd.series == 11) { + /* + * Attach routine that checks for an extended reset and releases it. + * This works around Errata 38.2.5 ref 9905 + */ + t->attach = samd11_attach; } if (protected) {