Align families

This commit is contained in:
Rasmus Melchior Jacobsen 2023-03-30 06:01:56 +02:00
parent 91d8afd371
commit e3c4e00be0
8 changed files with 55 additions and 58 deletions

View file

@ -122,6 +122,12 @@ impl Drop for Flash<'_> {
}
}
impl Drop for FlashLayout<'_> {
fn drop(&mut self) {
unsafe { family::lock() };
}
}
static REGION_LOCK: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
fn take_lock_spin() -> MutexGuard<'static, CriticalSectionRawMutex, ()> {

View file

@ -3,12 +3,10 @@ use core::ptr::write_volatile;
use atomic_polyfill::{fence, Ordering};
use super::{FlashRegion, FlashSector, BANK1, WRITE_SIZE};
use super::{FlashSector, BANK1_REGION, WRITE_SIZE};
use crate::flash::Error;
use crate::pac;
const ERASE_SIZE: usize = BANK1::SETTINGS.erase_size;
pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true));
}
@ -46,7 +44,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E
w.set_per(true);
});
pac::FLASH.ar().write(|w| w.set_far(sector.first));
pac::FLASH.ar().write(|w| w.set_far(sector.start));
pac::FLASH.cr().modify(|w| {
w.set_strt(true);
@ -103,11 +101,11 @@ unsafe fn blocking_wait_ready() -> Result<(), Error> {
}
pub(crate) fn get_sector(address: u32) -> FlashSector {
let sector_size = BANK1::SETTINGS.erase_size as u32;
let sector_size = BANK1_REGION.erase_size;
let index = address / sector_size;
FlashSector {
index: index as u8,
start: BANK1::SETTINGS.base as u32 + index * sector_size,
start: BANK1_REGION.base + index * sector_size,
size: sector_size,
}
}

View file

@ -84,9 +84,6 @@ mod alt_regions {
pub use alt_regions::AltFlashLayout;
fn is_dual_bank() -> bool {
// let asd: super::Bank1Region1;
// let sad = &super::BANK_1_REGION_1;
match FLASH_SIZE / 1024 {
// 1 MB devices depend on configuration
1024 => {

View file

@ -3,15 +3,12 @@ use core::ptr::write_volatile;
use atomic_polyfill::{fence, Ordering};
use super::{FlashRegion, FlashSector, BANK1, FLASH_SIZE, WRITE_SIZE};
use super::{FlashSector, BANK1_REGION, FLASH_REGIONS, WRITE_SIZE};
use crate::flash::Error;
use crate::pac;
const ERASE_SIZE: usize = BANK1::SETTINGS.erase_size;
const SECOND_BANK_OFFSET: usize = 0x0010_0000;
const fn is_dual_bank() -> bool {
FLASH_SIZE / 2 > ERASE_SIZE
FLASH_REGIONS.len() == 2
}
pub(crate) unsafe fn lock() {
@ -24,7 +21,6 @@ pub(crate) unsafe fn lock() {
pub(crate) unsafe fn unlock() {
pac::FLASH.bank(0).keyr().write(|w| w.set_keyr(0x4567_0123));
pac::FLASH.bank(0).keyr().write(|w| w.set_keyr(0xCDEF_89AB));
if is_dual_bank() {
pac::FLASH.bank(1).keyr().write(|w| w.set_keyr(0x4567_0123));
pac::FLASH.bank(1).keyr().write(|w| w.set_keyr(0xCDEF_89AB));
@ -39,7 +35,7 @@ pub(crate) unsafe fn end_write() {}
pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
// We cannot have the write setup sequence in begin_write as it depends on the address
let bank = if !is_dual_bank() || (start_address - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 {
let bank = if start_address < BANK1_REGION.end() {
pac::FLASH.bank(0)
} else {
pac::FLASH.bank(1)
@ -181,11 +177,11 @@ unsafe fn blocking_wait_ready(bank: pac::flash::Bank) -> Result<(), Error> {
}
pub(crate) fn get_sector(address: u32) -> FlashSector {
let sector_size = BANK1::SETTINGS.erase_size as u32;
let sector_size = BANK1_REGION.erase_size;
let index = address / sector_size;
FlashSector {
index: index as u8,
start: BANK1::SETTINGS.base as u32 + index * sector_size,
start: BANK1_REGION.base + index * sector_size,
size: sector_size,
}
}

View file

@ -2,7 +2,7 @@ use core::ptr::write_volatile;
use atomic_polyfill::{fence, Ordering};
use super::{FlashRegion, FlashSector, BANK1, WRITE_SIZE};
use super::{FlashSector, BANK1_REGION, WRITE_SIZE};
use crate::flash::Error;
use crate::pac;
@ -73,7 +73,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E
#[cfg(any(flash_wl, flash_wb, flash_l4))]
{
let idx = (sector.start - super::FLASH_BASE as u32) / BANK1::SETTINGS.erase_size as u32;
let idx = (sector.start - super::FLASH_BASE as u32) / BANK1_REGION.erase_size as u32;
#[cfg(flash_l4)]
let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) };
@ -182,11 +182,11 @@ unsafe fn blocking_wait_ready() -> Result<(), Error> {
}
pub(crate) fn get_sector(address: u32) -> FlashSector {
let sector_size = BANK1::SETTINGS.erase_size as u32;
let sector_size = BANK1_REGION.erase_size;
let index = address / sector_size;
FlashSector {
index: index as u8,
start: BANK1::SETTINGS.base as u32 + index * sector_size,
start: BANK1_REGION.base + index * sector_size,
size: sector_size,
}
}

View file

@ -24,9 +24,9 @@ pub struct FlashSector {
pub size: u32,
}
impl Drop for FlashLayout<'_> {
fn drop(&mut self) {
unsafe { family::lock() };
impl FlashRegion {
pub const fn end(&self) -> u32 {
self.base + self.size
}
}
@ -35,39 +35,13 @@ impl Drop for FlashLayout<'_> {
#[cfg_attr(flash_f4, path = "f4.rs")]
#[cfg_attr(flash_f7, path = "f7.rs")]
#[cfg_attr(flash_h7, path = "h7.rs")]
mod family;
#[cfg(not(any(
#[cfg_attr(
not(any(
flash_l0, flash_l1, flash_l4, flash_wl, flash_wb, flash_f3, flash_f4, flash_f7, flash_h7
)))]
mod family {
use super::{Error, FlashSector, WRITE_SIZE};
pub(crate) unsafe fn lock() {
unimplemented!();
}
pub(crate) unsafe fn unlock() {
unimplemented!();
}
pub(crate) unsafe fn begin_write() {
unimplemented!();
}
pub(crate) unsafe fn end_write() {
unimplemented!();
}
pub(crate) unsafe fn blocking_write(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
unimplemented!();
}
pub(crate) unsafe fn blocking_erase_sector(_sector: &FlashSector) -> Result<(), Error> {
unimplemented!();
}
pub(crate) unsafe fn clear_all_err() {
unimplemented!();
}
pub(crate) fn get_sector(_address: u32) -> FlashSector {
unimplemented!();
}
}
)),
path = "other.rs"
)]
mod family;
#[allow(unused_imports)]
pub use family::*;

View file

@ -0,0 +1,27 @@
#[allow(unused)]
use super::{Error, FlashSector, WRITE_SIZE};
pub(crate) unsafe fn lock() {
unimplemented!();
}
pub(crate) unsafe fn unlock() {
unimplemented!();
}
pub(crate) unsafe fn begin_write() {
unimplemented!();
}
pub(crate) unsafe fn end_write() {
unimplemented!();
}
pub(crate) unsafe fn blocking_write(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
unimplemented!();
}
pub(crate) unsafe fn blocking_erase_sector(_sector: &FlashSector) -> Result<(), Error> {
unimplemented!();
}
pub(crate) unsafe fn clear_all_err() {
unimplemented!();
}
pub(crate) fn get_sector(_address: u32) -> FlashSector {
unimplemented!();
}

View file

@ -43,7 +43,6 @@ pub mod i2c;
#[cfg(crc)]
pub mod crc;
#[cfg(flash)]
pub mod flash;
pub mod pwm;
#[cfg(quadspi)]