aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/flash/common.rs
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-04-05 10:27:13 +0200
committerRasmus Melchior Jacobsen <[email protected]>2023-04-05 10:27:13 +0200
commit95b31cf2db647b8d1779cc3f7439d5c7df98f379 (patch)
treed9a4b31dae641e4984f2b20fd060c43503bcb645 /embassy-stm32/src/flash/common.rs
parente2e15e436a63ea89a98c8f9f513ccb5e5a3fd115 (diff)
Remove Drop on Flash and FlashLayout and propage lifetime to region types
This allows the user to "split" the FlashRegions struct into each region
Diffstat (limited to 'embassy-stm32/src/flash/common.rs')
-rw-r--r--embassy-stm32/src/flash/common.rs20
1 files changed, 4 insertions, 16 deletions
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs
index c48b2f2ea..8235d6f08 100644
--- a/embassy-stm32/src/flash/common.rs
+++ b/embassy-stm32/src/flash/common.rs
@@ -38,18 +38,6 @@ impl<'d> Flash<'d> {
38 } 38 }
39} 39}
40 40
41impl Drop for Flash<'_> {
42 fn drop(&mut self) {
43 unsafe { family::lock() };
44 }
45}
46
47impl Drop for FlashLayout<'_> {
48 fn drop(&mut self) {
49 unsafe { family::lock() };
50 }
51}
52
53fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { 41fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
54 if offset + bytes.len() as u32 > size { 42 if offset + bytes.len() as u32 > size {
55 return Err(Error::Size); 43 return Err(Error::Size);
@@ -177,7 +165,7 @@ impl FlashRegion {
177 165
178foreach_flash_region! { 166foreach_flash_region! {
179 ($type_name:ident, $write_size:literal, $erase_size:literal) => { 167 ($type_name:ident, $write_size:literal, $erase_size:literal) => {
180 impl crate::_generated::flash_regions::$type_name { 168 impl crate::_generated::flash_regions::$type_name<'_> {
181 pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { 169 pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> {
182 blocking_read(self.0.base, self.0.size, offset, bytes) 170 blocking_read(self.0.base, self.0.size, offset, bytes)
183 } 171 }
@@ -191,11 +179,11 @@ foreach_flash_region! {
191 } 179 }
192 } 180 }
193 181
194 impl embedded_storage::nor_flash::ErrorType for crate::_generated::flash_regions::$type_name { 182 impl embedded_storage::nor_flash::ErrorType for crate::_generated::flash_regions::$type_name<'_> {
195 type Error = Error; 183 type Error = Error;
196 } 184 }
197 185
198 impl embedded_storage::nor_flash::ReadNorFlash for crate::_generated::flash_regions::$type_name { 186 impl embedded_storage::nor_flash::ReadNorFlash for crate::_generated::flash_regions::$type_name<'_> {
199 const READ_SIZE: usize = 1; 187 const READ_SIZE: usize = 1;
200 188
201 fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { 189 fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> {
@@ -207,7 +195,7 @@ foreach_flash_region! {
207 } 195 }
208 } 196 }
209 197
210 impl embedded_storage::nor_flash::NorFlash for crate::_generated::flash_regions::$type_name { 198 impl embedded_storage::nor_flash::NorFlash for crate::_generated::flash_regions::$type_name<'_> {
211 const WRITE_SIZE: usize = $write_size; 199 const WRITE_SIZE: usize = $write_size;
212 const ERASE_SIZE: usize = $erase_size; 200 const ERASE_SIZE: usize = $erase_size;
213 201