From fee89ed7c7f79d7e70421e7f0915c13bcfdefb2f Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Fri, 26 May 2023 15:23:36 +0200 Subject: [PATCH] Remove ability to set alt layout - it does not work. --- embassy-stm32/src/flash/asynch.rs | 2 +- embassy-stm32/src/flash/common.rs | 2 +- embassy-stm32/src/flash/f0.rs | 4 +++- embassy-stm32/src/flash/f3.rs | 4 +++- embassy-stm32/src/flash/f4.rs | 35 ++++++++----------------------- embassy-stm32/src/flash/f7.rs | 4 +++- embassy-stm32/src/flash/h7.rs | 4 +++- embassy-stm32/src/flash/l.rs | 4 +++- embassy-stm32/src/flash/other.rs | 4 +++- 9 files changed, 29 insertions(+), 34 deletions(-) diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs index a0d99495..3c3ece99 100644 --- a/embassy-stm32/src/flash/asynch.rs +++ b/embassy-stm32/src/flash/asynch.rs @@ -34,7 +34,7 @@ impl<'d> Flash<'d, Async> { } pub fn into_regions(self) -> FlashLayout<'d, Async> { - family::set_default_layout(); + assert!(family::is_default_layout()); FlashLayout::new(self.inner) } diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index cc0e2572..6c191290 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs @@ -30,7 +30,7 @@ impl<'d> Flash<'d, Blocking> { impl<'d, MODE> Flash<'d, MODE> { pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> { - family::set_default_layout(); + assert!(family::is_default_layout()); FlashLayout::new(self.inner) } diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs index e9916d14..02bd4cc1 100644 --- a/embassy-stm32/src/flash/f0.rs +++ b/embassy-stm32/src/flash/f0.rs @@ -7,7 +7,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn set_default_layout() {} +pub const fn is_default_layout() -> bool { + true +} pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index 4e65f558..b093a783 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs @@ -7,7 +7,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn set_default_layout() {} +pub const fn is_default_layout() -> bool { + true +} pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS diff --git a/embassy-stm32/src/flash/f4.rs b/embassy-stm32/src/flash/f4.rs index 25d96ca1..5e1fc696 100644 --- a/embassy-stm32/src/flash/f4.rs +++ b/embassy-stm32/src/flash/f4.rs @@ -69,7 +69,7 @@ mod alt_regions { impl<'d> Flash<'d> { pub fn into_alt_regions(self) -> AltFlashLayout<'d, Async> { - super::set_alt_layout(); + assert!(!super::is_default_layout()); // SAFETY: We never expose the cloned peripheral references, and their instance is not public. // Also, all async flash region operations are protected with a mutex. @@ -86,7 +86,7 @@ mod alt_regions { } pub fn into_alt_blocking_regions(self) -> AltFlashLayout<'d, Blocking> { - super::set_alt_layout(); + assert!(!super::is_default_layout()); // SAFETY: We never expose the cloned peripheral references, and their instance is not public. // Also, all blocking flash region operations are protected with a cs. @@ -191,38 +191,21 @@ impl FlashSector { } #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] -pub fn set_default_layout() { - unsafe { - pac::FLASH.optkeyr().write(|w| w.set_optkey(0x08192A3B)); - pac::FLASH.optkeyr().write(|w| w.set_optkey(0x4C5D6E7F)); - pac::FLASH.optcr().modify(|r| { - r.set_db1m(false); - r.set_optlock(true) - }); - }; +pub(crate) fn is_default_layout() -> bool { + unsafe { !pac::FLASH.optcr().read().db1m() } } #[cfg(not(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479)))] -pub const fn set_default_layout() {} - -#[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] -fn set_alt_layout() { - unsafe { - pac::FLASH.optkeyr().write(|w| w.set_optkey(0x08192A3B)); - pac::FLASH.optkeyr().write(|w| w.set_optkey(0x4C5D6E7F)); - pac::FLASH.optcr().modify(|r| { - r.set_db1m(true); - r.set_optlock(true) - }); - }; +pub(crate) const fn is_default_layout() -> bool { + true } #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f469, stm32f479))] pub fn get_flash_regions() -> &'static [&'static FlashRegion] { - if unsafe { pac::FLASH.optcr().read().db1m() } { - &ALT_FLASH_REGIONS - } else { + if is_default_layout() { &FLASH_REGIONS + } else { + &ALT_FLASH_REGIONS } } diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index e6267e17..1a6d6bb0 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -6,7 +6,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn set_default_layout() {} +pub const fn is_default_layout() -> bool { + true +} pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index d09ebc0d..9baf059e 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -7,7 +7,9 @@ use super::{FlashRegion, FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn set_default_layout() {} +pub const fn is_default_layout() -> bool { + true +} const fn is_dual_bank() -> bool { FLASH_REGIONS.len() == 2 diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index c4bbd547..deefd05e 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -6,7 +6,9 @@ use super::{FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; use crate::flash::Error; use crate::pac; -pub const fn set_default_layout() {} +pub const fn is_default_layout() -> bool { + true +} pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs index ccdcfeb7..a7e8d1d5 100644 --- a/embassy-stm32/src/flash/other.rs +++ b/embassy-stm32/src/flash/other.rs @@ -2,7 +2,9 @@ use super::{Error, FlashRegion, FlashSector, FLASH_REGIONS, WRITE_SIZE}; -pub const fn set_default_layout() {} +pub const fn is_default_layout() -> bool { + true +} pub const fn get_flash_regions() -> &'static [&'static FlashRegion] { &FLASH_REGIONS