aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Meadows2015-01-18 13:22:41 +0000
committerRichard Meadows2015-01-18 13:22:41 +0000
commit1c1312b467c60bed7ca6e81905c4436629153ae2 (patch)
tree144c212b9ffa7e14bb39d232eaf8fe4b3aa058e8
parenta3ab9b24d1c3b4dd6678fc88289f0cf397e52c6c (diff)
Added better feedback for samd erase failures
-rw-r--r--src/samd20.c22
1 files changed, 21 insertions, 1 deletions
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;
}