Skip to content

Commit 10a2d02

Browse files
committed
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.
1 parent 86b1686 commit 10a2d02

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313
- Replace UB code by a legitimate pointer access
1414
- Reexport `Direction` from `qei`
1515
- Add dac
16+
- Fix flash error flag clearing
1617

1718
## [v0.10.0] - 2022-12-12
1819

src/flash.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ impl<'a> FlashWriter<'a> {
166166
self.lock()?;
167167

168168
if sr.wrprterr().bit_is_set() {
169-
self.flash.sr.sr().modify(|_, w| w.wrprterr().clear_bit());
169+
// reset by writing 1
170+
self.flash.sr.sr().modify(|_, w| w.wrprterr().bit(true));
170171
Err(Error::EraseError)
171172
} else {
172173
if self.verify {
@@ -257,12 +258,14 @@ impl<'a> FlashWriter<'a> {
257258

258259
// Check for errors
259260
if self.flash.sr.sr().read().pgerr().bit_is_set() {
260-
self.flash.sr.sr().modify(|_, w| w.pgerr().clear_bit());
261+
// reset by writing 1
262+
self.flash.sr.sr().modify(|_, w| w.pgerr().bit(true));
261263

262264
self.lock()?;
263265
return Err(Error::ProgrammingError);
264266
} else if self.flash.sr.sr().read().wrprterr().bit_is_set() {
265-
self.flash.sr.sr().modify(|_, w| w.wrprterr().clear_bit());
267+
// reset by writing 1
268+
self.flash.sr.sr().modify(|_, w| w.wrprterr().bit(true));
266269

267270
self.lock()?;
268271
return Err(Error::WriteError);

0 commit comments

Comments
 (0)