Move new async to asynch module to guard for models without flash interrupt

This commit is contained in:
Rasmus Melchior Jacobsen 2023-05-25 23:51:10 +02:00
parent 74104aafda
commit e08267df54
9 changed files with 36 additions and 55 deletions

View file

@ -1,5 +1,9 @@
use core::marker::PhantomData;
use atomic_polyfill::{fence, Ordering};
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::into_ref;
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::mutex::Mutex;
@ -7,10 +11,28 @@ use super::{
blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE,
MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE,
};
use crate::peripherals::FLASH;
use crate::{interrupt, Peripheral};
pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
impl<'d> Flash<'d, Async> {
pub fn new(
p: impl Peripheral<P = FLASH> + 'd,
_irq: impl interrupt::Binding<crate::interrupt::FLASH, InterruptHandler> + 'd,
) -> Self {
into_ref!(p);
let flash_irq = unsafe { crate::interrupt::FLASH::steal() };
flash_irq.unpend();
flash_irq.enable();
Self {
inner: p,
_mode: PhantomData,
}
}
pub fn into_regions(self) -> FlashLayout<'d, Async> {
family::set_default_layout();
FlashLayout::new(self.inner)
@ -25,6 +47,15 @@ impl<'d> Flash<'d, Async> {
}
}
/// Interrupt handler
pub struct InterruptHandler;
impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
unsafe fn on_interrupt() {
family::on_interrupt();
}
}
impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> {
const READ_SIZE: usize = READ_SIZE;

View file

@ -1,7 +1,6 @@
use core::marker::PhantomData;
use atomic_polyfill::{fence, Ordering};
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
use embassy_hal_common::drop::OnDrop;
use embassy_hal_common::{into_ref, PeripheralRef};
use stm32_metapac::FLASH_BASE;
@ -11,29 +10,11 @@ use super::{
READ_SIZE, WRITE_SIZE,
};
use crate::peripherals::FLASH;
use crate::{interrupt, Peripheral};
use crate::Peripheral;
pub struct Flash<'d, MODE = Async> {
pub(crate) inner: PeripheralRef<'d, FLASH>,
_mode: PhantomData<MODE>,
}
impl<'d> Flash<'d, Async> {
pub fn new(
p: impl Peripheral<P = FLASH> + 'd,
_irq: impl interrupt::Binding<crate::interrupt::FLASH, InterruptHandler> + 'd,
) -> Self {
into_ref!(p);
let flash_irq = unsafe { crate::interrupt::FLASH::steal() };
flash_irq.unpend();
flash_irq.enable();
Self {
inner: p,
_mode: PhantomData,
}
}
pub(crate) _mode: PhantomData<MODE>,
}
impl<'d> Flash<'d, Blocking> {
@ -74,15 +55,6 @@ impl<'d, MODE> Flash<'d, MODE> {
}
}
/// Interrupt handler
pub struct InterruptHandler;
impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
unsafe fn on_interrupt() {
family::on_interrupt();
}
}
pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
if offset + bytes.len() as u32 > size {
return Err(Error::Size);

View file

@ -13,10 +13,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
&FLASH_REGIONS
}
pub(crate) unsafe fn on_interrupt() {
unimplemented!();
}
pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true));
}

View file

@ -13,10 +13,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
&FLASH_REGIONS
}
pub(crate) unsafe fn on_interrupt() {
unimplemented!();
}
pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true));
}

View file

@ -12,10 +12,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
&FLASH_REGIONS
}
pub(crate) unsafe fn on_interrupt() {
unimplemented!();
}
pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true));
}

View file

@ -17,10 +17,6 @@ pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
&FLASH_REGIONS
}
pub(crate) unsafe fn on_interrupt() {
unimplemented!();
}
pub(crate) unsafe fn lock() {
pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true));
if is_dual_bank() {

View file

@ -12,10 +12,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
&FLASH_REGIONS
}
pub(crate) unsafe fn on_interrupt() {
unimplemented!();
}
pub(crate) unsafe fn lock() {
#[cfg(any(flash_wl, flash_wb, flash_l4))]
pac::FLASH.cr().modify(|w| w.set_lock(true));

View file

@ -1,10 +1,12 @@
use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
#[cfg(all(feature = "nightly", flash_f4))]
pub mod asynch;
mod asynch;
#[cfg(flash)]
mod common;
#[cfg(all(feature = "nightly", flash_f4))]
pub use asynch::InterruptHandler;
#[cfg(flash)]
pub use common::*;

View file

@ -8,10 +8,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
&FLASH_REGIONS
}
pub(crate) unsafe fn on_interrupt() {
unimplemented!();
}
pub(crate) unsafe fn lock() {
unimplemented!();
}