aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-03-29 13:57:33 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-03-29 13:57:33 +0200
commit5a12fd6c75a41b976b2c935cbd8269fd03000a9a (patch)
treeb5c22bb945d45015caeed305604bcb1cfec56fda
parentb7dfc8de10ceddd6c2e8c078e529eb5e266ea7db (diff)
Add unimplemented family section
-rw-r--r--embassy-stm32/src/flash/mod.rs95
1 files changed, 61 insertions, 34 deletions
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs
index 89fdabd4d..d4e74553b 100644
--- a/embassy-stm32/src/flash/mod.rs
+++ b/embassy-stm32/src/flash/mod.rs
@@ -9,12 +9,45 @@ pub use crate::pac::{FLASH_BASE, FLASH_SIZE, WRITE_SIZE};
9use crate::peripherals::FLASH; 9use crate::peripherals::FLASH;
10use crate::Peripheral; 10use crate::Peripheral;
11 11
12#[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] 12#[cfg_attr(any(flash_l0, flash_l1, flash_l4, flash_wl, flash_wb), path = "l.rs")]
13#[cfg_attr(flash_f3, path = "f3.rs")] 13#[cfg_attr(flash_f3, path = "f3.rs")]
14#[cfg_attr(flash_f4, path = "f4.rs")] 14#[cfg_attr(flash_f4, path = "f4.rs")]
15#[cfg_attr(flash_f7, path = "f7.rs")] 15#[cfg_attr(flash_f7, path = "f7.rs")]
16#[cfg_attr(flash_h7, path = "h7.rs")] 16#[cfg_attr(flash_h7, path = "h7.rs")]
17mod family; 17mod family;
18
19#[cfg(not(any(
20 flash_l0, flash_l1, flash_l4, flash_wl, flash_wb, flash_f3, flash_f4, flash_f7, flash_h7
21)))]
22mod family {
23 use super::{Error, FlashSector};
24
25 pub(crate) unsafe fn lock() {
26 unimplemented!();
27 }
28 pub(crate) unsafe fn unlock() {
29 unimplemented!();
30 }
31 pub(crate) unsafe fn begin_write() {
32 unimplemented!();
33 }
34 pub(crate) unsafe fn end_write() {
35 unimplemented!();
36 }
37 pub(crate) unsafe fn blocking_write(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
38 unimplemented!();
39 }
40 pub(crate) unsafe fn blocking_erase_sector(_sector: &FlashSector) -> Result<(), Error> {
41 unimplemented!();
42 }
43 pub(crate) unsafe fn clear_all_err() {
44 unimplemented!();
45 }
46 pub(crate) fn get_sector(_address: u32) -> FlashSector {
47 unimplemented!();
48 }
49}
50
18pub struct Flash<'d> { 51pub struct Flash<'d> {
19 inner: PeripheralRef<'d, FLASH>, 52 inner: PeripheralRef<'d, FLASH>,
20} 53}
@@ -34,6 +67,33 @@ pub struct FlashSector {
34 pub size: u32, 67 pub size: u32,
35} 68}
36 69
70pub trait FlashRegion {
71 const SETTINGS: FlashRegionSettings;
72
73 fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
74 Flash::blocking_read_inner(Self::SETTINGS.base as u32 + offset, bytes)
75 }
76
77 fn blocking_write(&mut self, offset: u32, buf: &[u8]) -> Result<(), Error> {
78 let start_address = Self::SETTINGS.base as u32 + offset;
79
80 // Protect agains simultaneous write/erase to multiple regions.
81 let _guard = take_lock_spin();
82
83 unsafe { Flash::blocking_write_inner(start_address, buf) }
84 }
85
86 fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> {
87 let start_address = Self::SETTINGS.base as u32 + from;
88 let end_address = Self::SETTINGS.base as u32 + to;
89
90 // Protect agains simultaneous write/erase to multiple regions.
91 let _guard = take_lock_spin();
92
93 unsafe { Flash::blocking_erase_inner(start_address, end_address) }
94 }
95}
96
37static REGION_LOCK: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(()); 97static REGION_LOCK: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(());
38 98
39impl<'d> Flash<'d> { 99impl<'d> Flash<'d> {
@@ -151,39 +211,6 @@ impl Drop for FlashRegions<'_> {
151 } 211 }
152} 212}
153 213
154pub trait FlashRegion {
155 const SETTINGS: FlashRegionSettings;
156
157 fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
158 Flash::blocking_read_inner(Self::SETTINGS.base as u32 + offset, bytes)
159 }
160
161 fn blocking_write(&mut self, offset: u32, buf: &[u8]) -> Result<(), Error> {
162 let start_address = Self::SETTINGS.base as u32 + offset;
163
164 // Protect agains simultaneous write/erase to multiple regions.
165 let _guard = take_lock_spin();
166
167 unsafe {
168 family::clear_all_err();
169 Flash::blocking_write_inner(start_address, buf)
170 }
171 }
172
173 fn blocking_erase(&mut self, from: u32, to: u32) -> Result<(), Error> {
174 let start_address = Self::SETTINGS.base as u32 + from;
175 let end_address = Self::SETTINGS.base as u32 + to;
176
177 // Protect agains simultaneous write/erase to multiple regions.
178 let _guard = take_lock_spin();
179
180 unsafe {
181 family::clear_all_err();
182 Flash::blocking_erase_inner(start_address, end_address)
183 }
184 }
185}
186
187fn take_lock_spin() -> MutexGuard<'static, CriticalSectionRawMutex, ()> { 214fn take_lock_spin() -> MutexGuard<'static, CriticalSectionRawMutex, ()> {
188 loop { 215 loop {
189 if let Ok(guard) = REGION_LOCK.try_lock() { 216 if let Ok(guard) = REGION_LOCK.try_lock() {