Move new async to asynch module to guard for models without flash interrupt
This commit is contained in:
parent
74104aafda
commit
e08267df54
9 changed files with 36 additions and 55 deletions
|
@ -1,5 +1,9 @@
|
||||||
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use atomic_polyfill::{fence, Ordering};
|
use atomic_polyfill::{fence, Ordering};
|
||||||
|
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
|
||||||
use embassy_hal_common::drop::OnDrop;
|
use embassy_hal_common::drop::OnDrop;
|
||||||
|
use embassy_hal_common::into_ref;
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
use embassy_sync::mutex::Mutex;
|
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,
|
blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE,
|
||||||
MAX_ERASE_SIZE, READ_SIZE, WRITE_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(());
|
pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
|
||||||
|
|
||||||
impl<'d> Flash<'d, Async> {
|
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> {
|
pub fn into_regions(self) -> FlashLayout<'d, Async> {
|
||||||
family::set_default_layout();
|
family::set_default_layout();
|
||||||
FlashLayout::new(self.inner)
|
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> {
|
impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> {
|
||||||
const READ_SIZE: usize = READ_SIZE;
|
const READ_SIZE: usize = READ_SIZE;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
use atomic_polyfill::{fence, Ordering};
|
use atomic_polyfill::{fence, Ordering};
|
||||||
use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
|
|
||||||
use embassy_hal_common::drop::OnDrop;
|
use embassy_hal_common::drop::OnDrop;
|
||||||
use embassy_hal_common::{into_ref, PeripheralRef};
|
use embassy_hal_common::{into_ref, PeripheralRef};
|
||||||
use stm32_metapac::FLASH_BASE;
|
use stm32_metapac::FLASH_BASE;
|
||||||
|
@ -11,29 +10,11 @@ use super::{
|
||||||
READ_SIZE, WRITE_SIZE,
|
READ_SIZE, WRITE_SIZE,
|
||||||
};
|
};
|
||||||
use crate::peripherals::FLASH;
|
use crate::peripherals::FLASH;
|
||||||
use crate::{interrupt, Peripheral};
|
use crate::Peripheral;
|
||||||
|
|
||||||
pub struct Flash<'d, MODE = Async> {
|
pub struct Flash<'d, MODE = Async> {
|
||||||
pub(crate) inner: PeripheralRef<'d, FLASH>,
|
pub(crate) inner: PeripheralRef<'d, FLASH>,
|
||||||
_mode: PhantomData<MODE>,
|
pub(crate) _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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d> Flash<'d, Blocking> {
|
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> {
|
pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
|
||||||
if offset + bytes.len() as u32 > size {
|
if offset + bytes.len() as u32 > size {
|
||||||
return Err(Error::Size);
|
return Err(Error::Size);
|
||||||
|
|
|
@ -13,10 +13,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||||
&FLASH_REGIONS
|
&FLASH_REGIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn on_interrupt() {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||||
&FLASH_REGIONS
|
&FLASH_REGIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn on_interrupt() {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||||
&FLASH_REGIONS
|
&FLASH_REGIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn on_interrupt() {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,10 +17,6 @@ pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||||
&FLASH_REGIONS
|
&FLASH_REGIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn on_interrupt() {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true));
|
pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true));
|
||||||
if is_dual_bank() {
|
if is_dual_bank() {
|
||||||
|
|
|
@ -12,10 +12,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||||
&FLASH_REGIONS
|
&FLASH_REGIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn on_interrupt() {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
||||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
|
use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
|
||||||
|
|
||||||
#[cfg(all(feature = "nightly", flash_f4))]
|
#[cfg(all(feature = "nightly", flash_f4))]
|
||||||
pub mod asynch;
|
mod asynch;
|
||||||
#[cfg(flash)]
|
#[cfg(flash)]
|
||||||
mod common;
|
mod common;
|
||||||
|
|
||||||
|
#[cfg(all(feature = "nightly", flash_f4))]
|
||||||
|
pub use asynch::InterruptHandler;
|
||||||
#[cfg(flash)]
|
#[cfg(flash)]
|
||||||
pub use common::*;
|
pub use common::*;
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||||
&FLASH_REGIONS
|
&FLASH_REGIONS
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn on_interrupt() {
|
|
||||||
unimplemented!();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue