Align L family
This commit is contained in:
parent
47e07584ca
commit
47d5f127bb
1 changed files with 14 additions and 8 deletions
|
@ -1,9 +1,15 @@
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::ptr::write_volatile;
|
use core::ptr::write_volatile;
|
||||||
|
|
||||||
|
use super::FlashRegion;
|
||||||
use crate::flash::Error;
|
use crate::flash::Error;
|
||||||
use crate::pac;
|
use crate::pac;
|
||||||
|
|
||||||
|
const WRITE_SIZE: usize = super::BANK1::WRITE_SIZE;
|
||||||
|
const ERASE_SIZE: usize = super::BANK1::ERASE_SIZE;
|
||||||
|
pub(crate) const MAX_WRITE_SIZE: usize = WRITE_SIZE;
|
||||||
|
pub(crate) const MAX_ERASE_SIZE: usize = ERASE_SIZE;
|
||||||
|
|
||||||
pub(crate) unsafe fn lock() {
|
pub(crate) unsafe fn lock() {
|
||||||
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
||||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||||
|
@ -33,17 +39,17 @@ pub(crate) unsafe fn unlock() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> {
|
pub(crate) unsafe fn blocking_write(first_address: u32, buf: &[u8]) -> Result<(), Error> {
|
||||||
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
||||||
pac::FLASH.cr().write(|w| w.set_pg(true));
|
pac::FLASH.cr().write(|w| w.set_pg(true));
|
||||||
|
|
||||||
let ret = {
|
let ret = {
|
||||||
let mut ret: Result<(), Error> = Ok(());
|
let mut ret: Result<(), Error> = Ok(());
|
||||||
let mut offset = offset;
|
let mut address = first_address;
|
||||||
for chunk in buf.chunks(super::WRITE_SIZE) {
|
for chunk in buf.chunks(WRITE_SIZE) {
|
||||||
for val in chunk.chunks(4) {
|
for val in chunk.chunks(4) {
|
||||||
write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap()));
|
write_volatile(address as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap()));
|
||||||
offset += val.len() as u32;
|
address += val.len() as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = blocking_wait_ready();
|
ret = blocking_wait_ready();
|
||||||
|
@ -60,8 +66,8 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> {
|
pub(crate) unsafe fn blocking_erase(from_address: u32, to_address: u32) -> Result<(), Error> {
|
||||||
for page in (from..to).step_by(super::ERASE_SIZE) {
|
for page in (from_address..to_address).step_by(ERASE_SIZE) {
|
||||||
#[cfg(any(flash_l0, flash_l1))]
|
#[cfg(any(flash_l0, flash_l1))]
|
||||||
{
|
{
|
||||||
pac::FLASH.pecr().modify(|w| {
|
pac::FLASH.pecr().modify(|w| {
|
||||||
|
@ -74,7 +80,7 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> {
|
||||||
|
|
||||||
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
#[cfg(any(flash_wl, flash_wb, flash_l4))]
|
||||||
{
|
{
|
||||||
let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32;
|
let idx = (page - super::FLASH_BASE as u32) / ERASE_SIZE as u32;
|
||||||
|
|
||||||
#[cfg(flash_l4)]
|
#[cfg(flash_l4)]
|
||||||
let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) };
|
let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) };
|
||||||
|
|
Loading…
Reference in a new issue