From a8ceaa4dde3daa8a27d67cf0da24c936354a6e71 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Sun, 3 May 2020 15:11:51 -0700 Subject: [PATCH] Adding note for flash write failures - Not all families of EefcFlash support EEFC_FCMD_EWP on all regions of flash - This warning should save a lot of time during debugging - Helps with Issue #130 --- src/EefcFlash.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/EefcFlash.cpp b/src/EefcFlash.cpp index 4f614017..fef9004b 100644 --- a/src/EefcFlash.cpp +++ b/src/EefcFlash.cpp @@ -283,7 +283,23 @@ EefcFlash::writePage(uint32_t page) _wordCopy.setDstAddr(_addr + page * _size); _wordCopy.setSrcAddr(_onBufferA ? _pageBufferA : _pageBufferB); _onBufferA = !_onBufferA; - waitFSR(); + // Some chip families have page restrictions on calling EEFC_FCMD_EWP on all pages + // e.g. 16K boundary on SAM4S + // Print a warning indicating that the flash must be erased first + try + { + waitFSR(); + } + catch (FlashCmdError& exc) + { + if (page > 0) + { + printf("\nNOTE: Some chip families may not support auto-erase on all flash regions.\n"); + printf(" Try erasing the flash first (bossash), or erasing at the same time (bossac)."); + fflush(stdout); + } + throw; + } _wordCopy.runv(); if (_planes == 2 && page >= _pages / 2) writeFCR1(_eraseAuto ? EEFC_FCMD_EWP : EEFC_FCMD_WP, page - _pages / 2);