Let flash module be conditionally included

This commit is contained in:
Rasmus Melchior Jacobsen 2023-03-29 13:52:52 +02:00
parent ddbd509865
commit b7dfc8de10
4 changed files with 4 additions and 24 deletions

View File

@ -162,11 +162,13 @@ fn main() {
let regions_len = flash_memory_regions.len();
flash_regions.extend(quote! {
#[cfg(flash)]
pub struct FlashRegions<'d> {
_inner: embassy_hal_common::PeripheralRef<'d, crate::peripherals::FLASH>,
#(#fields),*
}
#[cfg(flash)]
impl<'d> FlashRegions<'d> {
pub(crate) const fn new(p: embassy_hal_common::PeripheralRef<'d, crate::peripherals::FLASH>) -> Self {
Self {

View File

@ -6,8 +6,6 @@ use super::{FlashRegion, FlashSector, BANK1, WRITE_SIZE};
use crate::flash::Error;
use crate::pac;
const ERASE_SIZE: usize = BANK1::SETTINGS.erase_size;
pub(crate) unsafe fn lock() {
#[cfg(any(flash_wl, flash_wb, flash_l4))]
pac::FLASH.cr().modify(|w| w.set_lock(true));
@ -75,7 +73,7 @@ pub(crate) unsafe fn blocking_erase_sector(sector: &FlashSector) -> Result<(), E
#[cfg(any(flash_wl, flash_wb, flash_l4))]
{
let idx = (sector.start - super::FLASH_BASE as u32) / ERASE_SIZE as u32;
let idx = (sector.start - super::FLASH_BASE as u32) / BANK1::SETTINGS.erase_size as u32;
#[cfg(flash_l4)]
let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) };

View File

@ -1,11 +0,0 @@
pub trait FlashRegion {
const SETTINGS: FlashRegionSettings;
}
pub struct FlashRegionSettings {
pub base: usize,
pub size: usize,
pub erase_size: usize,
pub write_size: usize,
pub erase_value: u8,
}

View File

@ -43,17 +43,8 @@ pub mod i2c;
#[cfg(crc)]
pub mod crc;
#[cfg(any(
flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f4, flash_f7, flash_h7
))]
#[cfg(flash)]
pub mod flash;
#[cfg(not(any(
flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f4, flash_f7, flash_h7
)))]
pub mod flash {
mod other;
pub use other::FlashRegion;
}
pub mod pwm;
#[cfg(rng)]
pub mod rng;