Align with new bind_interrupt
This commit is contained in:
@ -12,15 +12,18 @@ pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new
|
||||
|
||||
impl<'d> Flash<'d> {
|
||||
pub fn into_regions(self) -> FlashLayout<'d, Async> {
|
||||
assert!(!self.blocking_only);
|
||||
family::set_default_layout();
|
||||
FlashLayout::new(self.inner)
|
||||
}
|
||||
|
||||
pub async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Error> {
|
||||
assert!(!self.blocking_only);
|
||||
unsafe { write_chunked(FLASH_BASE as u32, FLASH_SIZE as u32, offset, bytes).await }
|
||||
}
|
||||
|
||||
pub async fn erase(&mut self, from: u32, to: u32) -> Result<(), Error> {
|
||||
assert!(!self.blocking_only);
|
||||
unsafe { erase_sectored(FLASH_BASE as u32, from, to).await }
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use atomic_polyfill::{fence, Ordering};
|
||||
use embassy_cortex_m::interrupt::InterruptExt;
|
||||
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;
|
||||
@ -9,21 +9,37 @@ use super::{
|
||||
WRITE_SIZE,
|
||||
};
|
||||
use crate::peripherals::FLASH;
|
||||
use crate::Peripheral;
|
||||
use crate::{interrupt, Peripheral};
|
||||
|
||||
pub struct Flash<'d> {
|
||||
pub(crate) inner: PeripheralRef<'d, FLASH>,
|
||||
pub(crate) blocking_only: bool,
|
||||
}
|
||||
|
||||
impl<'d> Flash<'d> {
|
||||
pub fn new(p: impl Peripheral<P = FLASH> + 'd, irq: impl Peripheral<P = crate::interrupt::FLASH> + 'd) -> Self {
|
||||
into_ref!(p, irq);
|
||||
pub fn new(
|
||||
p: impl Peripheral<P = FLASH> + 'd,
|
||||
_irq: impl interrupt::Binding<crate::interrupt::FLASH, InterruptHandler> + 'd,
|
||||
) -> Self {
|
||||
into_ref!(p);
|
||||
|
||||
irq.set_handler(family::on_interrupt);
|
||||
irq.unpend();
|
||||
irq.enable();
|
||||
let flash_irq = unsafe { crate::interrupt::FLASH::steal() };
|
||||
flash_irq.unpend();
|
||||
flash_irq.enable();
|
||||
|
||||
Self { inner: p }
|
||||
Self {
|
||||
inner: p,
|
||||
blocking_only: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_blocking_only(p: impl Peripheral<P = FLASH> + 'd) -> Self {
|
||||
into_ref!(p);
|
||||
|
||||
Self {
|
||||
inner: p,
|
||||
blocking_only: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_blocking_regions(self) -> FlashLayout<'d, Blocking> {
|
||||
@ -52,6 +68,15 @@ impl<'d> Flash<'d> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Interrupt handler
|
||||
pub struct InterruptHandler;
|
||||
|
||||
impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
|
||||
unsafe fn on_interrupt() {
|
||||
family::on_interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn read_blocking(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
|
||||
if offset + bytes.len() as u32 > size {
|
||||
return Err(Error::Size);
|
||||
|
@ -13,7 +13,7 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
@ -210,7 +210,7 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
// Clear IRQ flags
|
||||
pac::FLASH.sr().write(|w| {
|
||||
w.set_operr(true);
|
||||
|
@ -12,7 +12,7 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
|
||||
&FLASH_REGIONS
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn on_interrupt(_: *mut ()) {
|
||||
pub(crate) unsafe fn on_interrupt() {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user