aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/flash/common.rs21
-rw-r--r--embassy-stm32/src/flash/f0.rs10
-rw-r--r--embassy-stm32/src/flash/f3.rs10
-rw-r--r--embassy-stm32/src/flash/l.rs10
-rw-r--r--embassy-stm32/src/flash/other.rs4
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
86pub(super) fn blocking_read(base: u32, size: u32, offset: u32, bytes: &mut [u8]) -> Result<(), Error> { 86/// Interrupt handler
87pub struct InterruptHandler;
88
89impl interrupt::Handler<crate::interrupt::FLASH> for InterruptHandler {
90 unsafe fn on_interrupt() {
91 family::on_interrupt();
92 }
93}
94
95pub(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
39pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { 39pub(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
52pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { 52pub(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
95unsafe fn blocking_wait_ready() -> Result<(), Error> { 95unsafe 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
39pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { 39pub(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
52pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { 52pub(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
95unsafe fn blocking_wait_ready() -> Result<(), Error> { 95unsafe 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
60pub(crate) unsafe fn blocking_write(start_address: u32, buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { 60pub(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
73pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), Error> { 73pub(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
156unsafe fn blocking_wait_ready() -> Result<(), Error> { 156unsafe 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() {
24pub(crate) unsafe fn disable_blocking_write() { 24pub(crate) unsafe fn disable_blocking_write() {
25 unimplemented!(); 25 unimplemented!();
26} 26}
27pub(crate) unsafe fn blocking_write(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> { 27pub(crate) unsafe fn write_blocking(_start_address: u32, _buf: &[u8; WRITE_SIZE]) -> Result<(), Error> {
28 unimplemented!(); 28 unimplemented!();
29} 29}
30pub(crate) unsafe fn blocking_erase_sector(_sector: &FlashSector) -> Result<(), Error> { 30pub(crate) unsafe fn erase_sector_blocking(_sector: &FlashSector) -> Result<(), Error> {
31 unimplemented!(); 31 unimplemented!();
32} 32}
33pub(crate) unsafe fn clear_all_err() { 33pub(crate) unsafe fn clear_all_err() {