aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Melchior Jacobsen <[email protected]>2023-03-25 06:05:37 +0100
committerRasmus Melchior Jacobsen <[email protected]>2023-03-25 06:07:57 +0100
commit7edd72f8f542e81143d2375f1783418404d1dc58 (patch)
tree657fd61c155d3af9e572e872adda1f9b028b5159
parent6c73b23f384b4814ad9d13e8d108ef71464f72af (diff)
Align F3 family
-rw-r--r--embassy-stm32/src/flash/f3.rs21
1 files changed, 14 insertions, 7 deletions
diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs
index 1cb08ee1a..294fcffc2 100644
--- a/embassy-stm32/src/flash/f3.rs
+++ b/embassy-stm32/src/flash/f3.rs
@@ -1,9 +1,14 @@
1use core::convert::TryInto; 1use core::convert::TryInto;
2use core::mem::size_of;
2use core::ptr::write_volatile; 3use core::ptr::write_volatile;
3 4
5use super::FlashRegion;
4use crate::flash::Error; 6use crate::flash::Error;
5use crate::pac; 7use crate::pac;
6 8
9pub(crate) const MAX_WRITE_SIZE: usize = super::MAINA::WRITE_SIZE;
10pub(crate) const MAX_ERASE_SIZE: usize = super::MAINA::ERASE_SIZE;
11
7pub(crate) unsafe fn lock() { 12pub(crate) unsafe fn lock() {
8 pac::FLASH.cr().modify(|w| w.set_lock(true)); 13 pac::FLASH.cr().modify(|w| w.set_lock(true));
9} 14}
@@ -13,15 +18,17 @@ pub(crate) unsafe fn unlock() {
13 pac::FLASH.keyr().write(|w| w.set_fkeyr(0xCDEF_89AB)); 18 pac::FLASH.keyr().write(|w| w.set_fkeyr(0xCDEF_89AB));
14} 19}
15 20
16pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> { 21pub(crate) unsafe fn blocking_write(first_address: u32, buf: &[u8]) -> Result<(), Error> {
17 pac::FLASH.cr().write(|w| w.set_pg(true)); 22 pac::FLASH.cr().write(|w| w.set_pg(true));
18 23
19 let ret = { 24 let ret = {
20 let mut ret: Result<(), Error> = Ok(()); 25 let mut ret: Result<(), Error> = Ok(());
21 let mut offset = offset; 26 let mut address = first_address;
22 for chunk in buf.chunks(2) { 27 let chunks = buf.chunks_exact(size_of::<u16>());
23 write_volatile(offset as *mut u16, u16::from_le_bytes(chunk[0..2].try_into().unwrap())); 28 assert!(chunks.remainder().is_empty());
24 offset += chunk.len() as u32; 29 for chunk in chunks {
30 write_volatile(address as *mut u16, u16::from_le_bytes(chunk.try_into().unwrap()));
31 address += chunk.len() as u32;
25 32
26 ret = blocking_wait_ready(); 33 ret = blocking_wait_ready();
27 if ret.is_err() { 34 if ret.is_err() {
@@ -36,8 +43,8 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error
36 ret 43 ret
37} 44}
38 45
39pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { 46pub(crate) unsafe fn blocking_erase(from_address: u32, to_address: u32) -> Result<(), Error> {
40 for page in (from..to).step_by(super::ERASE_SIZE) { 47 for page in (from_address..to_address).step_by(MAX_ERASE_SIZE) {
41 pac::FLASH.cr().modify(|w| { 48 pac::FLASH.cr().modify(|w| {
42 w.set_per(true); 49 w.set_per(true);
43 }); 50 });