From 1c1312b467c60bed7ca6e81905c4436629153ae2 Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Sun, 18 Jan 2015 13:22:41 +0000 Subject: Added better feedback for samd erase failures --- src/samd20.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/samd20.c b/src/samd20.c index b252524..04ab737 100644 --- a/src/samd20.c +++ b/src/samd20.c @@ -501,14 +501,34 @@ static bool samd20_cmd_erase_all(target *t) { ADIv5_AP_t *ap = adiv5_target_ap(t); + /* Clear the DSU status bits */ + adiv5_ap_mem_write(ap, SAMD20_DSU_CTRLSTAT, + (SAMD20_STATUSA_DONE | SAMD20_STATUSA_PERR | SAMD20_STATUSA_FAIL)); + /* Erase all */ adiv5_ap_mem_write(ap, SAMD20_DSU_CTRLSTAT, SAMD20_CTRL_CHIP_ERASE); /* Poll for DSU Ready */ - while ((adiv5_ap_mem_read(ap, SAMD20_DSU_CTRLSTAT) & SAMD20_STATUSA_DONE) == 0) + uint32_t status; + while (((status = adiv5_ap_mem_read(ap, SAMD20_DSU_CTRLSTAT)) & + (SAMD20_STATUSA_DONE | SAMD20_STATUSA_PERR | SAMD20_STATUSA_FAIL)) == 0) if(target_check_error(t)) return false; + /* Test the protection error bit in Status A */ + if (status & SAMD20_STATUSA_PERR) { + gdb_outf("Erase failed due to a protection error.\n"); + return true; + } + + /* Test the fail bit in Status A */ + if (status & SAMD20_STATUSA_FAIL) { + gdb_outf("Erase failed.\n"); + return true; + } + + gdb_outf("Erase successful!\n"); + return true; } -- cgit v1.2.3