Skip to content

Commit

Permalink
Fix flash error flag clearing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nhpupu committed Jul 16, 2024
1 parent 86b1686 commit 10a2d02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions src/flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 10a2d02

Please sign in to comment.