diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-25 21:52:35 +0200 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-05-25 21:52:35 +0200 |
| commit | 983f01016becd0ab51fb542ec2c1ca6745df60cc (patch) | |
| tree | be88b8b023d2a7614fd808f96a14bcd1fd9eb079 | |
| parent | 9eca19b49d462e57308e8b13f7ff03e10cfb0557 (diff) | |
| parent | c02759ad91994191944b4fd1a4b47cd310416c04 (diff) | |
Merge branch 'async-flash' of https://github.com/rmja/embassy into async-flash
| -rw-r--r-- | embassy-stm32/src/flash/common.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f0.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/f3.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/l.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/flash/other.rs | 4 |
5 files changed, 32 insertions, 23 deletions
diff --git a/embassy-stm32/src/flash/common.rs b/embassy-stm32/src/flash/common.rs index 54c8d6812..1ea65c0b6 100644 --- a/embassy-stm32/src/flash/common.rs +++ b/embassy-stm32/src/flash/common.rs | |||
| @@ -83,7 +83,16 @@ impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler { | |||
| 83 | } | 83 | } |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { | 86 | /// Interrupt handler |
| 87 | pub struct InterruptHandler; | ||
| 88 | |||
| 89 | impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler { | ||
| 90 | unsafe fn on_interrupt() { | ||
| 91 | family::on_interrupt(); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | pub(super) fn read_blocking(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { | ||
| 87 | if offset + bytes.len() as u32 > size { | 96 | if offset + bytes.len() as u32 > size { |
| 88 | return Err(Error::Size); | 97 | return Err(Error::Size); |
| 89 | } | 98 | } |
| @@ -246,11 +255,11 @@ impl<MODE> embedded_storage::nor_flash::NorFlash for Flash<'_, MODE> { | |||
| 246 | const ERASE_SIZE: usize = MAX_ERASE_SIZE; | 255 | const ERASE_SIZE: usize = MAX_ERASE_SIZE; |
| 247 | 256 | ||
| 248 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { | 257 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { |
| 249 | self.blocking_write(offset, bytes) | 258 | self.write_blocking(offset, bytes) |
| 250 | } | 259 | } |
| 251 | 260 | ||
| 252 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | 261 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { |
| 253 | self.blocking_erase(from, to) | 262 | self.erase_blocking(from, to) |
| 254 | } | 263 | } |
| 255 | } | 264 | } |
| 256 | 265 | ||
| @@ -280,7 +289,7 @@ foreach_flash_region! { | |||
| 280 | const READ_SIZE: usize = READ_SIZE; | 289 | const READ_SIZE: usize = READ_SIZE; |
| 281 | 290 | ||
| 282 | fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { | 291 | fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error> { |
| 283 | self.blocking_read(offset, bytes) | 292 | self.read_blocking(offset, bytes) |
| 284 | } | 293 | } |
| 285 | 294 | ||
| 286 | fn capacity(&self) -> usize { | 295 | fn capacity(&self) -> usize { |
| @@ -293,11 +302,11 @@ foreach_flash_region! { | |||
| 293 | const ERASE_SIZE: usize = $erase_size; | 302 | const ERASE_SIZE: usize = $erase_size; |
| 294 | 303 | ||
| 295 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { | 304 | fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> { |
| 296 | self.blocking_write(offset, bytes) | 305 | self.write_blocking(offset, bytes) |
| 297 | } | 306 | } |
| 298 | 307 | ||
| 299 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { | 308 | fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> { |
| 300 | self.blocking_erase(from, to) | 309 | self.erase_blocking(from, to) |
| 301 | } | 310 | } |
| 302 | } | 311 | } |
| 303 | }; | 312 | }; |
diff --git a/embassy-stm32/src/flash/f0.rs b/embassy-stm32/src/flash/f0.rs index 9adf3fab2..cd17486e6 100644 --- a/embassy-stm32/src/flash/f0.rs +++ b/embassy-stm32/src/flash/f0.rs | |||
| @@ -36,7 +36,7 @@ pub(crate) unsafe fn disable_blocking_write() { | |||
| 36 | pac::FLASH.cr().write(|w| w.set_pg(false)); | 36 | pac::FLASH.cr().write(|w| w.set_pg(false)); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { | 39 | pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { |
| 40 | let mut address = start_address; | 40 | let mut address = start_address; |
| 41 | for chunk in buf.chunks(2) { | 41 | for chunk in buf.chunks(2) { |
| 42 | write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap())); | 42 | write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap())); |
| @@ -46,10 +46,10 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) | |||
| 46 | fence(Ordering::SeqCst); | 46 | fence(Ordering::SeqCst); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | blocking_wait_ready() | 49 | wait_ready_blocking() |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { | 52 | pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { |
| 53 | pac::FLASH.cr().modify(|w| { | 53 | pac::FLASH.cr().modify(|w| { |
| 54 | w.set_per(true); | 54 | w.set_per(true); |
| 55 | }); | 55 | }); |
| @@ -60,7 +60,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 60 | w.set_strt(true); | 60 | w.set_strt(true); |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | let mut ret: Result<(), Error> = blocking_wait_ready(); | 63 | let mut ret: Result<(), Error> = wait_ready_blocking(); |
| 64 | 64 | ||
| 65 | if !pac::FLASH.sr().read().eop() { | 65 | if !pac::FLASH.sr().read().eop() { |
| 66 | trace!("FLASH: EOP not set"); | 66 | trace!("FLASH: EOP not set"); |
| @@ -92,7 +92,7 @@ pub(crate) unsafe fn clear_all_err() { | |||
| 92 | }); | 92 | }); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | unsafe fn blocking_wait_ready() -> Result<(), Error> { | 95 | unsafe fn wait_ready_blocking() -> Result<(), Error> { |
| 96 | loop { | 96 | loop { |
| 97 | let sr = pac::FLASH.sr().read(); | 97 | let sr = pac::FLASH.sr().read(); |
| 98 | 98 | ||
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index b052b4d41..4ce391288 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs | |||
| @@ -36,7 +36,7 @@ pub(crate) unsafe fn disable_blocking_write() { | |||
| 36 | pac::FLASH.cr().write(|w| w.set_pg(false)); | 36 | pac::FLASH.cr().write(|w| w.set_pg(false)); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { | 39 | pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { |
| 40 | let mut address = start_address; | 40 | let mut address = start_address; |
| 41 | for chunk in buf.chunks(2) { | 41 | for chunk in buf.chunks(2) { |
| 42 | write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap())); | 42 | write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap())); |
| @@ -46,10 +46,10 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) | |||
| 46 | fence(Ordering::SeqCst); | 46 | fence(Ordering::SeqCst); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | blocking_wait_ready() | 49 | wait_ready_blocking() |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { | 52 | pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { |
| 53 | pac::FLASH.cr().modify(|w| { | 53 | pac::FLASH.cr().modify(|w| { |
| 54 | w.set_per(true); | 54 | w.set_per(true); |
| 55 | }); | 55 | }); |
| @@ -60,7 +60,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 60 | w.set_strt(true); | 60 | w.set_strt(true); |
| 61 | }); | 61 | }); |
| 62 | 62 | ||
| 63 | let mut ret: Result<(), Error> = blocking_wait_ready(); | 63 | let mut ret: Result<(), Error> = wait_ready_blocking(); |
| 64 | 64 | ||
| 65 | if !pac::FLASH.sr().read().eop() { | 65 | if !pac::FLASH.sr().read().eop() { |
| 66 | trace!("FLASH: EOP not set"); | 66 | trace!("FLASH: EOP not set"); |
| @@ -92,7 +92,7 @@ pub(crate) unsafe fn clear_all_err() { | |||
| 92 | }); | 92 | }); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | unsafe fn blocking_wait_ready() -> Result<(), Error> { | 95 | unsafe fn wait_ready_blocking() -> Result<(), Error> { |
| 96 | loop { | 96 | loop { |
| 97 | let sr = pac::FLASH.sr().read(); | 97 | let sr = pac::FLASH.sr().read(); |
| 98 | 98 | ||
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 76cad6d15..c2394e0c9 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs | |||
| @@ -57,7 +57,7 @@ pub(crate) unsafe fn disable_blocking_write() { | |||
| 57 | pac::FLASH.cr().write(|w| w.set_pg(false)); | 57 | pac::FLASH.cr().write(|w| w.set_pg(false)); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { | 60 | pub(crate) unsafe fn write_blocking(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { |
| 61 | let mut address = start_address; | 61 | let mut address = start_address; |
| 62 | for val in buf.chunks(4) { | 62 | for val in buf.chunks(4) { |
| 63 | write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap())); | 63 | write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap())); |
| @@ -67,10 +67,10 @@ pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) | |||
| 67 | fence(Ordering::SeqCst); | 67 | fence(Ordering::SeqCst); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | blocking_wait_ready() | 70 | wait_ready_blocking() |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { | 73 | pub(crate) unsafe fn erase_sector_blocking(sector: &FlashSector) -> Result<(), Error> { |
| 74 | #[cfg(any(flash_l0, flash_l1))] | 74 | #[cfg(any(flash_l0, flash_l1))] |
| 75 | { | 75 | { |
| 76 | pac::FLASH.pecr().modify(|w| { | 76 | pac::FLASH.pecr().modify(|w| { |
| @@ -100,7 +100,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E | |||
| 100 | }); | 100 | }); |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | let ret: Result<(), Error> = blocking_wait_ready(); | 103 | let ret: Result<(), Error> = wait_ready_blocking(); |
| 104 | 104 | ||
| 105 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | 105 | #[cfg(any(flash_wl, flash_wb, flash_l4))] |
| 106 | pac::FLASH.cr().modify(|w| w.set_per(false)); | 106 | pac::FLASH.cr().modify(|w| w.set_per(false)); |
| @@ -153,7 +153,7 @@ pub(crate) unsafe fn clear_all_err() { | |||
| 153 | }); | 153 | }); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | unsafe fn blocking_wait_ready() -> Result<(), Error> { | 156 | unsafe fn wait_ready_blocking() -> Result<(), Error> { |
| 157 | loop { | 157 | loop { |
| 158 | let sr = pac::FLASH.sr().read(); | 158 | let sr = pac::FLASH.sr().read(); |
| 159 | 159 | ||
diff --git a/embassy-stm32/src/flash/other.rs b/embassy-stm32/src/flash/other.rs index c007f1178..e569951f9 100644 --- a/embassy-stm32/src/flash/other.rs +++ b/embassy-stm32/src/flash/other.rs | |||
| @@ -24,10 +24,10 @@ pub(crate) unsafe fn enable_blocking_write() { | |||
| 24 | pub(crate) unsafe fn disable_blocking_write() { | 24 | pub(crate) unsafe fn disable_blocking_write() { |
| 25 | unimplemented!(); | 25 | unimplemented!(); |
| 26 | } | 26 | } |
| 27 | pub(crate) unsafe fn blocking_write(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { | 27 | pub(crate) unsafe fn write_blocking(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { |
| 28 | unimplemented!(); | 28 | unimplemented!(); |
| 29 | } | 29 | } |
| 30 | pub(crate) unsafe fn blocking_erase_sector(_sector: &FlashSector) -> Result<(), Error> { | 30 | pub(crate) unsafe fn erase_sector_blocking(_sector: &FlashSector) -> Result<(), Error> { |
| 31 | unimplemented!(); | 31 | unimplemented!(); |
| 32 | } | 32 | } |
| 33 | pub(crate) unsafe fn clear_all_err() { | 33 | pub(crate) unsafe fn clear_all_err() { |
