Change region type name
This commit is contained in:
parent
47d5f127bb
commit
73ccc04231
@ -111,7 +111,7 @@ fn main() {
|
||||
.iter()
|
||||
.filter(|x| x.kind == MemoryRegionKind::Flash && x.settings.is_some());
|
||||
for region in flash_memory_regions.clone() {
|
||||
let region_name = format_ident!("{}", region.name.replace("_", ""));
|
||||
let region_name = format_ident!("{}", get_flash_region_name(region.name));
|
||||
let base = region.address as usize;
|
||||
let size = region.size as usize;
|
||||
let settings = region.settings.as_ref().unwrap();
|
||||
@ -120,6 +120,7 @@ fn main() {
|
||||
let erase_value = settings.erase_value;
|
||||
|
||||
flash_regions.extend(quote! {
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct #region_name(());
|
||||
});
|
||||
|
||||
@ -136,9 +137,9 @@ fn main() {
|
||||
|
||||
let (fields, inits): (Vec<TokenStream>, Vec<TokenStream>) = flash_memory_regions
|
||||
.map(|f| {
|
||||
let trimmed_name = f.name.replace("_", "");
|
||||
let field_name = format_ident!("{}", trimmed_name.to_lowercase());
|
||||
let field_type = format_ident!("{}", trimmed_name);
|
||||
let region_name = get_flash_region_name(f.name);
|
||||
let field_name = format_ident!("{}", region_name.to_lowercase());
|
||||
let field_type = format_ident!("{}", region_name);
|
||||
let field = quote! {
|
||||
pub #field_name: #field_type
|
||||
};
|
||||
@ -633,7 +634,7 @@ fn main() {
|
||||
.filter(|m| m.kind == MemoryRegionKind::Flash && m.settings.is_some())
|
||||
{
|
||||
let mut row = Vec::new();
|
||||
row.push(m.name.replace("_", ""));
|
||||
row.push(get_flash_region_name(m.name));
|
||||
flash_regions_table.push(row);
|
||||
}
|
||||
|
||||
@ -886,3 +887,7 @@ macro_rules! {} {{
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn get_flash_region_name(name: &str) -> String {
|
||||
name.replace("BANK_", "BANK").replace("REGION_", "REGION")
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ use super::FlashRegion;
|
||||
use crate::flash::Error;
|
||||
use crate::pac;
|
||||
|
||||
pub(crate) const MAX_WRITE_SIZE: usize = super::MAINA::WRITE_SIZE;
|
||||
pub(crate) const MAX_ERASE_SIZE: usize = super::MAINA::ERASE_SIZE;
|
||||
pub(crate) const MAX_WRITE_SIZE: usize = super::BANK1::WRITE_SIZE;
|
||||
pub(crate) const MAX_ERASE_SIZE: usize = super::BANK1::ERASE_SIZE;
|
||||
|
||||
pub(crate) unsafe fn lock() {
|
||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||
|
@ -5,12 +5,12 @@ use core::sync::atomic::{fence, Ordering};
|
||||
|
||||
use embassy_hal_common::stm32::flash::f4::{get_sector, SECOND_BANK_SECTOR_OFFSET};
|
||||
|
||||
use super::{FlashRegion, FLASH_SIZE, MAINC};
|
||||
use super::{FlashRegion, FLASH_SIZE};
|
||||
use crate::flash::Error;
|
||||
use crate::pac;
|
||||
|
||||
pub(crate) const MAX_WRITE_SIZE: usize = MAINC::WRITE_SIZE;
|
||||
pub(crate) const MAX_ERASE_SIZE: usize = MAINC::ERASE_SIZE;
|
||||
pub(crate) const MAX_WRITE_SIZE: usize = super::BANK1_REGION3::WRITE_SIZE;
|
||||
pub(crate) const MAX_ERASE_SIZE: usize = super::BANK1_REGION3::ERASE_SIZE;
|
||||
|
||||
unsafe fn is_dual_bank() -> bool {
|
||||
match FLASH_SIZE / 1024 {
|
||||
@ -46,13 +46,13 @@ pub(crate) unsafe fn blocking_write(first_address: u32, buf: &[u8]) -> Result<()
|
||||
|
||||
let ret = {
|
||||
let mut ret: Result<(), Error> = Ok(());
|
||||
let mut offset = first_address;
|
||||
let mut address = first_address;
|
||||
for chunk in buf.chunks(MAX_WRITE_SIZE) {
|
||||
let vals = chunk.chunks_exact(size_of::<u32>());
|
||||
assert!(vals.remainder().is_empty());
|
||||
for val in vals {
|
||||
write_volatile(offset as *mut u32, u32::from_le_bytes(val.try_into().unwrap()));
|
||||
offset += val.len() as u32;
|
||||
write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap()));
|
||||
address += val.len() as u32;
|
||||
|
||||
// prevents parallelism errors
|
||||
fence(Ordering::SeqCst);
|
||||
|
@ -9,8 +9,8 @@ use super::FlashRegion;
|
||||
use crate::flash::Error;
|
||||
use crate::pac;
|
||||
|
||||
pub(crate) const MAX_WRITE_SIZE: usize = super::MAINC::WRITE_SIZE;
|
||||
pub(crate) const MAX_ERASE_SIZE: usize = super::MAINC::ERASE_SIZE;
|
||||
pub(crate) const MAX_WRITE_SIZE: usize = super::BANK1_REGION3::WRITE_SIZE;
|
||||
pub(crate) const MAX_ERASE_SIZE: usize = super::BANK1_REGION3::ERASE_SIZE;
|
||||
|
||||
pub(crate) unsafe fn lock() {
|
||||
pac::FLASH.cr().modify(|w| w.set_lock(true));
|
||||
|
Loading…
Reference in New Issue
Block a user