1492: Remove ability to, during runtime, set alt layout - it does not work. r=rmja a=rmja

I wasted yesterday trying to get this to work. It seems that erase operations does not work when in db1m mode. The erase operations, both bank and sector, runs and completes without any error flags being set. It also takes expected amount of time, but the flash is not actually erased.
I found [this](https://community.st.com/s/question/0D50X00009XkWrASAV/is-it-possilbe-to-checkand-may-be-writethe-db1m-option-byte-from-the-firmware-i-am-using-an-stmf4427ig-1mb-with-double-bank-via-db1m-option-byte) on the topic, at it seems that one have to reset the mcu for the change to take effect, so it does not make any sense to have it as runtime configurable.

Co-authored-by: Rasmus Melchior Jacobsen <rmja@laesoe.org>
This commit is contained in:
bors[bot] 2023-05-26 13:58:59 +00:00 committed by GitHub
commit ee20fd4c16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 34 deletions

View file

@ -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)
}

View file

@ -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)
}

View file

@ -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

View file

@ -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

View file

@ -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
}
}

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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