aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-05-25 23:51:10 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-05-25 23:51:10 +0200
commite08267df54a78106f4c03958346c81ae7e169bd6 (patch)
treea70fb50b336dd171617dcafe709a88ab3376c957
parent74104aafda4a16b7be66f8d1634fc4b663721c49 (diff)
Move new async to asynch module to guard for models without flash interrupt
-rw-r--r--embassy-stm32/src/flash/asynch.rs31
-rw-r--r--embassy-stm32/src/flash/common.rs32
-rw-r--r--embassy-stm32/src/flash/f0.rs4
-rw-r--r--embassy-stm32/src/flash/f3.rs4
-rw-r--r--embassy-stm32/src/flash/f7.rs4
-rw-r--r--embassy-stm32/src/flash/h7.rs4
-rw-r--r--embassy-stm32/src/flash/l.rs4
-rw-r--r--embassy-stm32/src/flash/mod.rs4
-rw-r--r--embassy-stm32/src/flash/other.rs4
9 files changed, 36 insertions, 55 deletions
diff --git a/embassy-stm32/src/flash/asynch.rs b/embassy-stm32/src/flash/asynch.rs
index de53f6c8f..6ad1e90d4 100644
--- a/embassy-stm32/src/flash/asynch.rs
+++ b/embassy-stm32/src/flash/asynch.rs
@@ -1,5 +1,9 @@
1use core::marker::PhantomData;
2
1use atomic_polyfill::{fence, Ordering}; 3use atomic_polyfill::{fence, Ordering};
4use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
2use embassy_hal_common::drop::OnDrop; 5use embassy_hal_common::drop::OnDrop;
6use embassy_hal_common::into_ref;
3use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; 7use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
4use embassy_sync::mutex::Mutex; 8use embassy_sync::mutex::Mutex;
5 9
@@ -7,10 +11,28 @@ use super::{
7 blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE, 11 blocking_read, ensure_sector_aligned, family, get_sector, Async, Error, Flash, FlashLayout, FLASH_BASE, FLASH_SIZE,
8 MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE, 12 MAX_ERASE_SIZE, READ_SIZE, WRITE_SIZE,
9}; 13};
14use crate::peripherals::FLASH;
15use crate::{interrupt, Peripheral};
10 16
11pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(()); 17pub(super) static REGION_ACCESS: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
12 18
13impl<'d> Flash<'d, Async> { 19impl<'d> Flash<'d, Async> {
20 pub fn new(
21 p: impl Peripheral<P = FLASH> + 'd,
22 _irq: impl interrupt::Binding<crate::interrupt::FLASH, InterruptHandler> + 'd,
23 ) -> Self {
24 into_ref!(p);
25
26 let flash_irq = unsafe { crate::interrupt::FLASH::steal() };
27 flash_irq.unpend();
28 flash_irq.enable();
29
30 Self {
31 inner: p,
32 _mode: PhantomData,
33 }
34 }
35
14 pub fn into_regions(self) -> FlashLayout<'d, Async> { 36 pub fn into_regions(self) -> FlashLayout<'d, Async> {
15 family::set_default_layout(); 37 family::set_default_layout();
16 FlashLayout::new(self.inner) 38 FlashLayout::new(self.inner)
@@ -25,6 +47,15 @@ impl<'d> Flash<'d, Async> {
25 } 47 }
26} 48}
27 49
50/// Interrupt handler
51pub struct InterruptHandler;
52
53impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
54 unsafe fn on_interrupt() {
55 family::on_interrupt();
56 }
57}
58
28impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> { 59impl embedded_storage_async::nor_flash::ReadNorFlash for Flash<'_, Async> {
29 const READ_SIZE: usize = READ_SIZE; 60 const READ_SIZE: usize = READ_SIZE;
30 61
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index c190eaf9a..cc0e2572b 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -1,7 +1,6 @@
1use core::marker::PhantomData; 1use core::marker::PhantomData;
2 2
3use atomic_polyfill::{fence, Ordering}; 3use atomic_polyfill::{fence, Ordering};
4use embassy_cortex_m::interrupt::{Interrupt, InterruptExt};
5use embassy_hal_common::drop::OnDrop; 4use embassy_hal_common::drop::OnDrop;
6use embassy_hal_common::{into_ref, PeripheralRef}; 5use embassy_hal_common::{into_ref, PeripheralRef};
7use stm32_metapac::FLASH_BASE; 6use stm32_metapac::FLASH_BASE;
@@ -11,29 +10,11 @@ use super::{
11 READ_SIZE, WRITE_SIZE, 10 READ_SIZE, WRITE_SIZE,
12}; 11};
13use crate::peripherals::FLASH; 12use crate::peripherals::FLASH;
14use crate::{interrupt, Peripheral}; 13use crate::Peripheral;
15 14
16pub struct Flash<'d, MODE = Async> { 15pub struct Flash<'d, MODE = Async> {
17 pub(crate) inner: PeripheralRef<'d, FLASH>, 16 pub(crate) inner: PeripheralRef<'d, FLASH>,
18 _mode: PhantomData<MODE>, 17 pub(crate) _mode: PhantomData<MODE>,
19}
20
21impl<'d> Flash<'d, Async> {
22 pub fn new(
23 p: impl Peripheral<P = FLASH> + 'd,
24 _irq: impl interrupt::Binding<crate::interrupt::FLASH, InterruptHandler> + 'd,
25 ) -> Self {
26 into_ref!(p);
27
28 let flash_irq = unsafe { crate::interrupt::FLASH::steal() };
29 flash_irq.unpend();
30 flash_irq.enable();
31
32 Self {
33 inner: p,
34 _mode: PhantomData,
35 }
36 }
37} 18}
38 19
39impl<'d> Flash<'d, Blocking> { 20impl<'d> Flash<'d, Blocking> {
@@ -74,15 +55,6 @@ impl<'d, MODE> Flash<'d, MODE> {
74 } 55 }
75} 56}
76 57
77/// Interrupt handler
78pub struct InterruptHandler;
79
80impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
81 unsafe fn on_interrupt() {
82 family::on_interrupt();
83 }
84}
85
86pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { 58pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
87 if offset + bytes.len() as u32 > size { 59 if offset + bytes.len() as u32 > size {
88 return Err(Error::Size); 60 return Err(Error::Size);
diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs
index bf601f05c..e9916d14b 100644
--- a/embassy-stm32/src/flash/f0.rs
+++ b/embassy-stm32/src/flash/f0.rs
@@ -13,10 +13,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS 13 &FLASH_REGIONS
14} 14}
15 15
16pub(crate) unsafe fn on_interrupt() {
17 unimplemented!();
18}
19
20pub(crate) unsafe fn lock() { 16pub(crate) unsafe fn lock() {
21 pac::FLASH.cr().modify(|w| w.set_lock(true)); 17 pac::FLASH.cr().modify(|w| w.set_lock(true));
22} 18}
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs
index 5b566a62f..4e65f5580 100644
--- a/embassy-stm32/src/flash/f3.rs
+++ b/embassy-stm32/src/flash/f3.rs
@@ -13,10 +13,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
13 &FLASH_REGIONS 13 &FLASH_REGIONS
14} 14}
15 15
16pub(crate) unsafe fn on_interrupt() {
17 unimplemented!();
18}
19
20pub(crate) unsafe fn lock() { 16pub(crate) unsafe fn lock() {
21 pac::FLASH.cr().modify(|w| w.set_lock(true)); 17 pac::FLASH.cr().modify(|w| w.set_lock(true));
22} 18}
diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs
index f0c6bf81d..e6267e178 100644
--- a/embassy-stm32/src/flash/f7.rs
+++ b/embassy-stm32/src/flash/f7.rs
@@ -12,10 +12,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
12 &FLASH_REGIONS 12 &FLASH_REGIONS
13} 13}
14 14
15pub(crate) unsafe fn on_interrupt() {
16 unimplemented!();
17}
18
19pub(crate) unsafe fn lock() { 15pub(crate) unsafe fn lock() {
20 pac::FLASH.cr().modify(|w| w.set_lock(true)); 16 pac::FLASH.cr().modify(|w| w.set_lock(true));
21} 17}
diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs
index ee824ed2b..d09ebc0dd 100644
--- a/embassy-stm32/src/flash/h7.rs
+++ b/embassy-stm32/src/flash/h7.rs
@@ -17,10 +17,6 @@ pub fn get_flash_regions() -> &'static [&'static FlashRegion] {
17 &FLASH_REGIONS 17 &FLASH_REGIONS
18} 18}
19 19
20pub(crate) unsafe fn on_interrupt() {
21 unimplemented!();
22}
23
24pub(crate) unsafe fn lock() { 20pub(crate) unsafe fn lock() {
25 pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true)); 21 pac::FLASH.bank(0).cr().modify(|w| w.set_lock(true));
26 if is_dual_bank() { 22 if is_dual_bank() {
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs
index 0a5b6301e..c4bbd5477 100644
--- a/embassy-stm32/src/flash/l.rs
+++ b/embassy-stm32/src/flash/l.rs
@@ -12,10 +12,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
12 &FLASH_REGIONS 12 &FLASH_REGIONS
13} 13}
14 14
15pub(crate) unsafe fn on_interrupt() {
16 unimplemented!();
17}
18
19pub(crate) unsafe fn lock() { 15pub(crate) unsafe fn lock() {
20 #[cfg(any(flash_wl, flash_wb, flash_l4))] 16 #[cfg(any(flash_wl, flash_wb, flash_l4))]
21 pac::FLASH.cr().modify(|w| w.set_lock(true)); 17 pac::FLASH.cr().modify(|w| w.set_lock(true));
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs
index 02f6c5320..2cc92f518 100644
--- a/embassy-stm32/src/flash/mod.rs
+++ b/embassy-stm32/src/flash/mod.rs
@@ -1,10 +1,12 @@
1use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind}; 1use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
2 2
3#[cfg(all(feature = "nightly", flash_f4))] 3#[cfg(all(feature = "nightly", flash_f4))]
4pub mod asynch; 4mod asynch;
5#[cfg(flash)] 5#[cfg(flash)]
6mod common; 6mod common;
7 7
8#[cfg(all(feature = "nightly", flash_f4))]
9pub use asynch::InterruptHandler;
8#[cfg(flash)] 10#[cfg(flash)]
9pub use common::*; 11pub use common::*;
10 12
diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs
index c007f1178..ccdcfeb7a 100644
--- a/embassy-stm32/src/flash/other.rs
+++ b/embassy-stm32/src/flash/other.rs
@@ -8,10 +8,6 @@ pub const fn get_flash_regions() -> &'static [&'static FlashRegion] {
8 &FLASH_REGIONS 8 &FLASH_REGIONS
9} 9}
10 10
11pub(crate) unsafe fn on_interrupt() {
12 unimplemented!();
13}
14
15pub(crate) unsafe fn lock() { 11pub(crate) unsafe fn lock() {
16 unimplemented!(); 12 unimplemented!();
17} 13}