diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-03-25 13:30:24 +0100 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-03-25 13:30:24 +0100 |
| commit | 47d5f127bb307f441bc7765d6d053ce41168ce53 (patch) | |
| tree | 146707da9c2eb45a2a038f68c574d2aa5c28ec52 | |
| parent | 47e07584cacf9b632736185d95be2f703df9a8f8 (diff) | |
Align L family
| -rw-r--r-- | embassy-stm32/src/flash/l.rs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index 5048a3314..9ab732b8b 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs | |||
| @@ -1,9 +1,15 @@ | |||
| 1 | use core::convert::TryInto; | 1 | use core::convert::TryInto; |
| 2 | use core::ptr::write_volatile; | 2 | use core::ptr::write_volatile; |
| 3 | 3 | ||
| 4 | use super::FlashRegion; | ||
| 4 | use crate::flash::Error; | 5 | use crate::flash::Error; |
| 5 | use crate::pac; | 6 | use crate::pac; |
| 6 | 7 | ||
| 8 | const WRITE_SIZE: usize = super::BANK1::WRITE_SIZE; | ||
| 9 | const ERASE_SIZE: usize = super::BANK1::ERASE_SIZE; | ||
| 10 | pub(crate) const MAX_WRITE_SIZE: usize = WRITE_SIZE; | ||
| 11 | pub(crate) const MAX_ERASE_SIZE: usize = ERASE_SIZE; | ||
| 12 | |||
| 7 | pub(crate) unsafe fn lock() { | 13 | pub(crate) unsafe fn lock() { |
| 8 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | 14 | #[cfg(any(flash_wl, flash_wb, flash_l4))] |
| 9 | pac::FLASH.cr().modify(|w| w.set_lock(true)); | 15 | pac::FLASH.cr().modify(|w| w.set_lock(true)); |
| @@ -33,17 +39,17 @@ pub(crate) unsafe fn unlock() { | |||
| 33 | } | 39 | } |
| 34 | } | 40 | } |
| 35 | 41 | ||
| 36 | pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> { | 42 | pub(crate) unsafe fn blocking_write(first_address: u32, buf: &[u8]) -> Result<(), Error> { |
| 37 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | 43 | #[cfg(any(flash_wl, flash_wb, flash_l4))] |
| 38 | pac::FLASH.cr().write(|w| w.set_pg(true)); | 44 | pac::FLASH.cr().write(|w| w.set_pg(true)); |
| 39 | 45 | ||
| 40 | let ret = { | 46 | let ret = { |
| 41 | let mut ret: Result<(), Error> = Ok(()); | 47 | let mut ret: Result<(), Error> = Ok(()); |
| 42 | let mut offset = offset; | 48 | let mut address = first_address; |
| 43 | for chunk in buf.chunks(super::WRITE_SIZE) { | 49 | for chunk in buf.chunks(WRITE_SIZE) { |
| 44 | for val in chunk.chunks(4) { | 50 | for val in chunk.chunks(4) { |
| 45 | write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); | 51 | write_volatile(address as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); |
| 46 | offset += val.len() as u32; | 52 | address += val.len() as u32; |
| 47 | } | 53 | } |
| 48 | 54 | ||
| 49 | ret = blocking_wait_ready(); | 55 | ret = blocking_wait_ready(); |
| @@ -60,8 +66,8 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error | |||
| 60 | ret | 66 | ret |
| 61 | } | 67 | } |
| 62 | 68 | ||
| 63 | pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { | 69 | pub(crate) unsafe fn blocking_erase(from_address: u32, to_address: u32) -> Result<(), Error> { |
| 64 | for page in (from..to).step_by(super::ERASE_SIZE) { | 70 | for page in (from_address..to_address).step_by(ERASE_SIZE) { |
| 65 | #[cfg(any(flash_l0, flash_l1))] | 71 | #[cfg(any(flash_l0, flash_l1))] |
| 66 | { | 72 | { |
| 67 | pac::FLASH.pecr().modify(|w| { | 73 | pac::FLASH.pecr().modify(|w| { |
| @@ -74,7 +80,7 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { | |||
| 74 | 80 | ||
| 75 | #[cfg(any(flash_wl, flash_wb, flash_l4))] | 81 | #[cfg(any(flash_wl, flash_wb, flash_l4))] |
| 76 | { | 82 | { |
| 77 | let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32; | 83 | let idx = (page - super::FLASH_BASE as u32) / ERASE_SIZE as u32; |
| 78 | 84 | ||
| 79 | #[cfg(flash_l4)] | 85 | #[cfg(flash_l4)] |
| 80 | let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) }; | 86 | let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) }; |
