diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-03-29 12:10:24 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-03-29 12:10:24 +0200 |
| commit | 4ee3d15519aaf3a290fd78063b88d182ff3aab53 (patch) | |
| tree | 9f3c8ad811b2d8c63cd50815f14788f6348895c3 /embassy-stm32/src | |
| parent | 6806bb969278acc9d3cde34897453b29807157c1 (diff) | |
Keep peripheral lifetime when calling into_regions()
Diffstat (limited to 'embassy-stm32/src')
| -rw-r--r-- | embassy-stm32/src/flash/mod.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 29db2d132..1d1f034aa 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs | |||
| @@ -16,7 +16,7 @@ use crate::Peripheral; | |||
| 16 | mod family; | 16 | mod family; |
| 17 | 17 | ||
| 18 | pub struct Flash<'d> { | 18 | pub struct Flash<'d> { |
| 19 | _inner: PeripheralRef<'d, FLASH>, | 19 | inner: PeripheralRef<'d, FLASH>, |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | pub struct FlashRegionSettings { | 22 | pub struct FlashRegionSettings { |
| @@ -39,11 +39,13 @@ static REGION_LOCK: Mutex<CriticalSectionRawMutex, ()> = Mutex::new(()); | |||
| 39 | impl<'d> Flash<'d> { | 39 | impl<'d> Flash<'d> { |
| 40 | pub fn new(p: impl Peripheral<P = FLASH> + 'd) -> Self { | 40 | pub fn new(p: impl Peripheral<P = FLASH> + 'd) -> Self { |
| 41 | into_ref!(p); | 41 | into_ref!(p); |
| 42 | Self { _inner: p } | 42 | Self { inner: p } |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | pub fn into_regions(self) -> FlashRegions { | 45 | pub fn into_regions(self) -> FlashRegions<'d> { |
| 46 | FlashRegions::take() | 46 | let mut flash = self; |
| 47 | let p = unsafe { flash.inner.clone_unchecked() }; | ||
| 48 | FlashRegions::new(p) | ||
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { | 51 | pub fn blocking_read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { |
| @@ -123,7 +125,7 @@ impl Drop for Flash<'_> { | |||
| 123 | } | 125 | } |
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | impl Drop for FlashRegions { | 128 | impl Drop for FlashRegions<'_> { |
| 127 | fn drop(&mut self) { | 129 | fn drop(&mut self) { |
| 128 | unsafe { family::lock() }; | 130 | unsafe { family::lock() }; |
| 129 | } | 131 | } |
