From 1e9923e618a291a8a52b62c446bdb02dc681f305 Mon Sep 17 00:00:00 2001 From: Maxime Borges Date: Fri, 28 Jan 2022 17:28:12 +0100 Subject: [PATCH 1/2] flash: use mer[12] fields for erase on big chips --- src/flash.rs | 58 +++++++++++++++++++++++++++++++++++++++++++--------- src/lib.rs | 12 +---------- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/src/flash.rs b/src/flash.rs index cdee369..21b5f3f 100644 --- a/src/flash.rs +++ b/src/flash.rs @@ -172,12 +172,29 @@ impl<'a> EraseSequence<'a> { //TODO: This should check if sector_number is valid for this device flash.registers.cr.modify(|_, w| unsafe { - w.mer() - .clear_bit() - .ser() - .set_bit() - .snb() - .bits(sector_number) + #[cfg(any( + feature = "stm32f765", + feature = "stm32f767", + feature = "stm32f769", + feature = "stm32f777", + feature = "stm32f778", + feature = "stm32f779", + ))] + w + .mer1().clear_bit() + .mer2().clear_bit(); + #[cfg(not(any( + feature = "stm32f765", + feature = "stm32f767", + feature = "stm32f769", + feature = "stm32f777", + feature = "stm32f778", + feature = "stm32f779", + )))] + w.mer().clear_bit(); + w + .ser().set_bit() + .snb().bits(sector_number) }); flash.registers.cr.modify(|_, w| w.strt().start()); @@ -189,10 +206,31 @@ impl<'a> EraseSequence<'a> { flash.check_locked_or_busy()?; flash.clear_errors(); - flash - .registers - .cr - .modify(|_, w| w.mer().set_bit().ser().clear_bit()); + flash.registers.cr.modify(|_, w| unsafe { + #[cfg(any( + feature = "stm32f765", + feature = "stm32f767", + feature = "stm32f769", + feature = "stm32f777", + feature = "stm32f778", + feature = "stm32f779", + ))] + w + .mer1().set_bit() + .mer2().set_bit(); + #[cfg(not(any( + feature = "stm32f765", + feature = "stm32f767", + feature = "stm32f769", + feature = "stm32f777", + feature = "stm32f778", + feature = "stm32f779", + )))] + w.mer().clear_bit(); + w + .ser().clear_bit() + }); + flash.registers.cr.modify(|_, w| w.strt().start()); Ok(Self { flash }) diff --git a/src/lib.rs b/src/lib.rs index 9c48fac..27973e9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -160,17 +160,7 @@ pub mod qei; #[cfg(feature = "ltdc")] pub mod ltdc; -#[cfg(all( - feature = "device-selected", - not(any( - feature = "stm32f765", - feature = "stm32f767", - feature = "stm32f769", - feature = "stm32f777", - feature = "stm32f778", - feature = "stm32f779", - )) -))] +#[cfg(feature = "device-selected")] pub mod flash; pub mod state { From 4ab36933f04ee4f7d525cd9d399f86759a2260e9 Mon Sep 17 00:00:00 2001 From: Maxime Borges Date: Tue, 8 Feb 2022 17:52:31 +0100 Subject: [PATCH 2/2] Fixed formating --- src/flash.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/flash.rs b/src/flash.rs index 21b5f3f..1437665 100644 --- a/src/flash.rs +++ b/src/flash.rs @@ -180,9 +180,7 @@ impl<'a> EraseSequence<'a> { feature = "stm32f778", feature = "stm32f779", ))] - w - .mer1().clear_bit() - .mer2().clear_bit(); + w.mer1().clear_bit().mer2().clear_bit(); #[cfg(not(any( feature = "stm32f765", feature = "stm32f767", @@ -192,9 +190,7 @@ impl<'a> EraseSequence<'a> { feature = "stm32f779", )))] w.mer().clear_bit(); - w - .ser().set_bit() - .snb().bits(sector_number) + w.ser().set_bit().snb().bits(sector_number) }); flash.registers.cr.modify(|_, w| w.strt().start()); @@ -215,9 +211,7 @@ impl<'a> EraseSequence<'a> { feature = "stm32f778", feature = "stm32f779", ))] - w - .mer1().set_bit() - .mer2().set_bit(); + w.mer1().set_bit().mer2().set_bit(); #[cfg(not(any( feature = "stm32f765", feature = "stm32f767", @@ -227,10 +221,9 @@ impl<'a> EraseSequence<'a> { feature = "stm32f779", )))] w.mer().clear_bit(); - w - .ser().clear_bit() + w.ser().clear_bit() }); - + flash.registers.cr.modify(|_, w| w.strt().start()); Ok(Self { flash })