From 10a2d02463f5eefa58fcb3150a798e7da6351967 Mon Sep 17 00:00:00 2001 From: pupu Date: Tue, 16 Jul 2024 21:10:14 +0800 Subject: [PATCH] Fix flash error flag clearing According to the STM32F10xxx Flash programming manual [(PM0068, p22)](https://www.st.com/resource/en/programming_manual/pm0068-stm32f10xxx-xldensity-flash-programming-stmicroelectronics.pdf), WRPRTERR and PGERR flags are cleared by writing 1. The original code incorrectly attempted to clear these flags by writing 0, causing them to remain set after an error occurred. This prevented further flash operations until reset. This commit corrects the flag clearing operation, allowing flash operations to continue after recoverable errors. --- CHANGELOG.md | 1 + src/flash.rs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edf2c3fb..ed11be36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Replace UB code by a legitimate pointer access - Reexport `Direction` from `qei` - Add dac +- Fix flash error flag clearing ## [v0.10.0] - 2022-12-12 diff --git a/src/flash.rs b/src/flash.rs index 605eb4ab..4dba3bed 100644 --- a/src/flash.rs +++ b/src/flash.rs @@ -166,7 +166,8 @@ impl<'a> FlashWriter<'a> { self.lock()?; if sr.wrprterr().bit_is_set() { - self.flash.sr.sr().modify(|_, w| w.wrprterr().clear_bit()); + // reset by writing 1 + self.flash.sr.sr().modify(|_, w| w.wrprterr().bit(true)); Err(Error::EraseError) } else { if self.verify { @@ -257,12 +258,14 @@ impl<'a> FlashWriter<'a> { // Check for errors if self.flash.sr.sr().read().pgerr().bit_is_set() { - self.flash.sr.sr().modify(|_, w| w.pgerr().clear_bit()); + // reset by writing 1 + self.flash.sr.sr().modify(|_, w| w.pgerr().bit(true)); self.lock()?; return Err(Error::ProgrammingError); } else if self.flash.sr.sr().read().wrprterr().bit_is_set() { - self.flash.sr.sr().modify(|_, w| w.wrprterr().clear_bit()); + // reset by writing 1 + self.flash.sr.sr().modify(|_, w| w.wrprterr().bit(true)); self.lock()?; return Err(Error::WriteError);