From f02ef7af8f3b2aec6799695c796beed4f4c00482 Mon Sep 17 00:00:00 2001 From: Michael Kefeder Date: Mon, 1 Feb 2021 19:03:23 +0100 Subject: [PATCH] Wait for EEFC flash to complete operations before resetting --- src/D2xNvmFlash.cpp | 5 +++++ src/D2xNvmFlash.h | 2 ++ src/D5xNvmFlash.cpp | 5 +++++ src/D5xNvmFlash.h | 2 ++ src/EefcFlash.cpp | 11 +++++++++-- src/EefcFlash.h | 6 ++++-- src/EfcFlash.cpp | 10 ++++++++-- src/EfcFlash.h | 6 ++++-- src/Flash.h | 4 +++- src/bossac.cpp | 15 +++++++++------ 10 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/D2xNvmFlash.cpp b/src/D2xNvmFlash.cpp index 0974936c..f959bd09 100644 --- a/src/D2xNvmFlash.cpp +++ b/src/D2xNvmFlash.cpp @@ -258,6 +258,11 @@ D2xNvmFlash::writeOptions() } } +void +D2xNvmFlash::ready() +{ +} + void D2xNvmFlash::writePage(uint32_t page) { diff --git a/src/D2xNvmFlash.h b/src/D2xNvmFlash.h index d7c36948..9d6d4d39 100644 --- a/src/D2xNvmFlash.h +++ b/src/D2xNvmFlash.h @@ -56,6 +56,8 @@ class D2xNvmFlash : public Flash void writeOptions(); + void ready(); + void writePage(uint32_t page); void readPage(uint32_t page, uint8_t* data); diff --git a/src/D5xNvmFlash.cpp b/src/D5xNvmFlash.cpp index 81e5583f..883b3fb4 100644 --- a/src/D5xNvmFlash.cpp +++ b/src/D5xNvmFlash.cpp @@ -253,6 +253,11 @@ D5xNvmFlash::writeOptions() } } +void +D5xNvmFlash::ready() +{ +} + void D5xNvmFlash::writePage(uint32_t page) { diff --git a/src/D5xNvmFlash.h b/src/D5xNvmFlash.h index d266f588..d5854c64 100644 --- a/src/D5xNvmFlash.h +++ b/src/D5xNvmFlash.h @@ -56,6 +56,8 @@ class D5xNvmFlash : public Flash void writeOptions(); + void ready(); + void writePage(uint32_t page); void readPage(uint32_t page, uint8_t* data); diff --git a/src/EefcFlash.cpp b/src/EefcFlash.cpp index 4f614017..4ccc9a1a 100644 --- a/src/EefcFlash.cpp +++ b/src/EefcFlash.cpp @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -274,6 +274,13 @@ EefcFlash::writeOptions() } } +void +EefcFlash::ready() +{ + // wait for Flash operations to be done + waitFSR(); +} + void EefcFlash::writePage(uint32_t page) { diff --git a/src/EefcFlash.h b/src/EefcFlash.h index 40fabc1a..ebcc567d 100644 --- a/src/EefcFlash.h +++ b/src/EefcFlash.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -68,6 +68,8 @@ class EefcFlash : public Flash void writeOptions(); + void ready(); + void writePage(uint32_t page); void readPage(uint32_t page, uint8_t* data); diff --git a/src/EfcFlash.cpp b/src/EfcFlash.cpp index 9b212385..7e40ad68 100644 --- a/src/EfcFlash.cpp +++ b/src/EfcFlash.cpp @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -212,6 +212,12 @@ EfcFlash::writeOptions() } } + +void +EfcFlash::ready() +{ +} + void EfcFlash::writePage(uint32_t page) { diff --git a/src/EfcFlash.h b/src/EfcFlash.h index cf22f0b8..3409cdf6 100644 --- a/src/EfcFlash.h +++ b/src/EfcFlash.h @@ -3,7 +3,7 @@ // // Copyright (c) 2011-2018, ShumaTech // All rights reserved. -// +// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // * Redistributions of source code must retain the above copyright @@ -14,7 +14,7 @@ // * Neither the name of the nor the // names of its contributors may be used to endorse or promote products // derived from this software without specific prior written permission. -// +// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -67,6 +67,8 @@ class EfcFlash : public Flash void writeOptions(); + void ready(); + void writePage(uint32_t page); void readPage(uint32_t page, uint8_t* data); diff --git a/src/Flash.h b/src/Flash.h index 5d3a37b3..bf096428 100644 --- a/src/Flash.h +++ b/src/Flash.h @@ -97,7 +97,7 @@ class FlashOption void set(const T& value) { _value = value; _dirty = true; } const T& get() { return _value; } bool isDirty() { return _dirty; } - + private: T _value; bool _dirty; @@ -149,6 +149,8 @@ class Flash virtual void writeOptions() = 0; + virtual void ready() = 0; + virtual void writePage(uint32_t page) = 0; virtual void readPage(uint32_t page, uint8_t* data) = 0; diff --git a/src/bossac.cpp b/src/bossac.cpp index 11ebcade..38b3abd4 100644 --- a/src/bossac.cpp +++ b/src/bossac.cpp @@ -113,7 +113,7 @@ class BossaObserver : public FlasherObserver public: BossaObserver() : _lastTicks(-1) {} virtual ~BossaObserver() {} - + virtual void onStatus(const char *message, ...); virtual void onProgress(int num, int div); private: @@ -124,7 +124,7 @@ void BossaObserver::onStatus(const char *message, ...) { va_list ap; - + va_start(ap, message); vprintf(message, ap); va_end(ap); @@ -137,10 +137,10 @@ BossaObserver::onProgress(int num, int div) int bars = 30; ticks = num * bars / div; - + if (ticks == _lastTicks) return; - + printf("\r["); while (ticks-- > 0) { @@ -153,7 +153,7 @@ BossaObserver::onProgress(int num, int div) } printf("] %d%% (%d/%d pages)", num * 100 / div, num, div); fflush(stdout); - + _lastTicks = 0; } @@ -490,8 +490,11 @@ main(int argc, char* argv[]) flash->writeOptions(); - if (config.reset) + if (config.reset) { + // Ensure flash operation are complete prior to reset + flash->ready(); device.reset(); + } } catch (exception& e) {