Change region type name

This commit is contained in:
Rasmus Melchior Jacobsen 2023-03-25 13:39:10 +01:00
parent 47d5f127bb
commit 73ccc04231
4 changed files with 20 additions and 15 deletions

View File

@ -111,7 +111,7 @@ fn main() {
.iter() .iter()
.filter(|x| x.kind == MemoryRegionKind::Flash && x.settings.is_some()); .filter(|x| x.kind == MemoryRegionKind::Flash && x.settings.is_some());
for region in flash_memory_regions.clone() { 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 base = region.address as usize;
let size = region.size as usize; let size = region.size as usize;
let settings = region.settings.as_ref().unwrap(); let settings = region.settings.as_ref().unwrap();
@ -120,6 +120,7 @@ fn main() {
let erase_value = settings.erase_value; let erase_value = settings.erase_value;
flash_regions.extend(quote! { flash_regions.extend(quote! {
#[allow(non_camel_case_types)]
pub struct #region_name(()); pub struct #region_name(());
}); });
@ -136,9 +137,9 @@ fn main() {
let (fields, inits): (Vec<TokenStream>, Vec<TokenStream>) = flash_memory_regions let (fields, inits): (Vec<TokenStream>, Vec<TokenStream>) = flash_memory_regions
.map(|f| { .map(|f| {
let trimmed_name = f.name.replace("_", ""); let region_name = get_flash_region_name(f.name);
let field_name = format_ident!("{}", trimmed_name.to_lowercase()); let field_name = format_ident!("{}", region_name.to_lowercase());
let field_type = format_ident!("{}", trimmed_name); let field_type = format_ident!("{}", region_name);
let field = quote! { let field = quote! {
pub #field_name: #field_type pub #field_name: #field_type
}; };
@ -633,7 +634,7 @@ fn main() {
.filter(|m| m.kind == MemoryRegionKind::Flash && m.settings.is_some()) .filter(|m| m.kind == MemoryRegionKind::Flash && m.settings.is_some())
{ {
let mut row = Vec::new(); let mut row = Vec::new();
row.push(m.name.replace("_", "")); row.push(get_flash_region_name(m.name));
flash_regions_table.push(row); flash_regions_table.push(row);
} }
@ -886,3 +887,7 @@ macro_rules! {} {{
) )
.unwrap(); .unwrap();
} }
fn get_flash_region_name(name: &str) -> String {
name.replace("BANK_", "BANK").replace("REGION_", "REGION")
}

View File

@ -6,8 +6,8 @@ use super::FlashRegion;
use crate::flash::Error; use crate::flash::Error;
use crate::pac; use crate::pac;
pub(crate) const MAX_WRITE_SIZE: usize = super::MAINA::WRITE_SIZE; pub(crate) const MAX_WRITE_SIZE: usize = super::BANK1::WRITE_SIZE;
pub(crate) const MAX_ERASE_SIZE: usize = super::MAINA::ERASE_SIZE; pub(crate) const MAX_ERASE_SIZE: usize = super::BANK1::ERASE_SIZE;
pub(crate) unsafe fn lock() { pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true)); pac::FLASH.cr().modify(|w| w.set_lock(true));

View File

@ -5,12 +5,12 @@ use core::sync::atomic::{fence, Ordering};
use embassy_hal_common::stm32::flash::f4::{get_sector, SECOND_BANK_SECTOR_OFFSET}; 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::flash::Error;
use crate::pac; use crate::pac;
pub(crate) const MAX_WRITE_SIZE: usize = MAINC::WRITE_SIZE; pub(crate) const MAX_WRITE_SIZE: usize = super::BANK1_REGION3::WRITE_SIZE;
pub(crate) const MAX_ERASE_SIZE: usize = MAINC::ERASE_SIZE; pub(crate) const MAX_ERASE_SIZE: usize = super::BANK1_REGION3::ERASE_SIZE;
unsafe fn is_dual_bank() -> bool { unsafe fn is_dual_bank() -> bool {
match FLASH_SIZE / 1024 { match FLASH_SIZE / 1024 {
@ -46,13 +46,13 @@ pub(crate) unsafe fn blocking_write(first_address: u32, buf: &[u8]) -> Result<()
let ret = { let ret = {
let mut ret: Result<(), Error> = Ok(()); let mut ret: Result<(), Error> = Ok(());
let mut offset = first_address; let mut address = first_address;
for chunk in buf.chunks(MAX_WRITE_SIZE) { for chunk in buf.chunks(MAX_WRITE_SIZE) {
let vals = chunk.chunks_exact(size_of::<u32>()); let vals = chunk.chunks_exact(size_of::<u32>());
assert!(vals.remainder().is_empty()); assert!(vals.remainder().is_empty());
for val in vals { for val in vals {
write_volatile(offset as *mut u32, u32::from_le_bytes(val.try_into().unwrap())); write_volatile(address as *mut u32, u32::from_le_bytes(val.try_into().unwrap()));
offset += val.len() as u32; address += val.len() as u32;
// prevents parallelism errors // prevents parallelism errors
fence(Ordering::SeqCst); fence(Ordering::SeqCst);

View File

@ -9,8 +9,8 @@ use super::FlashRegion;
use crate::flash::Error; use crate::flash::Error;
use crate::pac; use crate::pac;
pub(crate) const MAX_WRITE_SIZE: usize = super::MAINC::WRITE_SIZE; pub(crate) const MAX_WRITE_SIZE: usize = super::BANK1_REGION3::WRITE_SIZE;
pub(crate) const MAX_ERASE_SIZE: usize = super::MAINC::ERASE_SIZE; pub(crate) const MAX_ERASE_SIZE: usize = super::BANK1_REGION3::ERASE_SIZE;
pub(crate) unsafe fn lock() { pub(crate) unsafe fn lock() {
pac::FLASH.cr().modify(|w| w.set_lock(true)); pac::FLASH.cr().modify(|w| w.set_lock(true));