2023-03-29 15:45:18 +02:00
|
|
|
use embedded_storage::nor_flash::{NorFlashError, NorFlashErrorKind};
|
2022-04-20 13:49:59 +02:00
|
|
|
|
2023-05-26 00:31:41 +02:00
|
|
|
#[cfg(flash_f4)]
|
2023-05-25 23:51:10 +02:00
|
|
|
mod asynch;
|
2023-03-30 05:27:57 +02:00
|
|
|
#[cfg(flash)]
|
|
|
|
mod common;
|
|
|
|
|
2023-05-26 00:31:41 +02:00
|
|
|
#[cfg(flash_f4)]
|
2023-05-25 23:51:10 +02:00
|
|
|
pub use asynch::InterruptHandler;
|
2023-03-30 05:27:57 +02:00
|
|
|
#[cfg(flash)]
|
|
|
|
pub use common::*;
|
|
|
|
|
|
|
|
pub use crate::_generated::flash_regions::*;
|
2023-04-18 15:49:33 +02:00
|
|
|
pub use crate::_generated::MAX_ERASE_SIZE;
|
2023-03-30 05:27:57 +02:00
|
|
|
pub use crate::pac::{FLASH_BASE, FLASH_SIZE, WRITE_SIZE};
|
|
|
|
|
2023-05-24 12:17:12 +02:00
|
|
|
pub const READ_SIZE: usize = 1;
|
|
|
|
|
2023-05-24 17:24:28 +02:00
|
|
|
pub struct Blocking;
|
|
|
|
pub struct Async;
|
|
|
|
|
2023-03-30 09:17:14 +02:00
|
|
|
#[derive(Debug)]
|
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
2023-03-30 05:27:57 +02:00
|
|
|
pub struct FlashRegion {
|
2023-03-30 08:32:36 +02:00
|
|
|
pub bank: FlashBank,
|
2023-03-30 05:27:57 +02:00
|
|
|
pub base: u32,
|
|
|
|
pub size: u32,
|
|
|
|
pub erase_size: u32,
|
|
|
|
pub write_size: u32,
|
|
|
|
pub erase_value: u8,
|
2023-05-23 22:49:27 +02:00
|
|
|
pub(crate) _ensure_internal: (),
|
2023-03-30 05:27:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq)]
|
2023-03-30 09:17:14 +02:00
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
2023-03-30 05:27:57 +02:00
|
|
|
pub struct FlashSector {
|
2023-03-30 08:32:36 +02:00
|
|
|
pub bank: FlashBank,
|
|
|
|
pub index_in_bank: u8,
|
2023-03-30 05:27:57 +02:00
|
|
|
pub start: u32,
|
|
|
|
pub size: u32,
|
|
|
|
}
|
|
|
|
|
2023-03-30 08:32:36 +02:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
2023-03-30 09:17:14 +02:00
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
2023-03-30 08:32:36 +02:00
|
|
|
pub enum FlashBank {
|
|
|
|
Bank1 = 0,
|
|
|
|
Bank2 = 1,
|
|
|
|
Otp,
|
|
|
|
}
|
|
|
|
|
2023-03-30 06:01:56 +02:00
|
|
|
impl FlashRegion {
|
|
|
|
pub const fn end(&self) -> u32 {
|
|
|
|
self.base + self.size
|
2023-03-30 05:27:57 +02:00
|
|
|
}
|
2023-03-30 08:32:36 +02:00
|
|
|
|
|
|
|
pub const fn sectors(&self) -> u8 {
|
|
|
|
(self.size / self.erase_size) as u8
|
|
|
|
}
|
2023-03-30 05:27:57 +02:00
|
|
|
}
|
|
|
|
|
2023-03-29 13:57:33 +02:00
|
|
|
#[cfg_attr(any(flash_l0, flash_l1, flash_l4, flash_wl, flash_wb), path = "l.rs")]
|
2023-05-14 21:57:31 +02:00
|
|
|
#[cfg_attr(flash_f0, path = "f0.rs")]
|
2022-05-02 15:36:02 +02:00
|
|
|
#[cfg_attr(flash_f3, path = "f3.rs")]
|
2022-07-11 02:57:46 +02:00
|
|
|
#[cfg_attr(flash_f4, path = "f4.rs")]
|
2022-05-03 16:16:37 +02:00
|
|
|
#[cfg_attr(flash_f7, path = "f7.rs")]
|
2023-07-31 10:26:16 +02:00
|
|
|
#[cfg_attr(flash_g0, path = "g0.rs")]
|
2022-05-06 09:21:29 +02:00
|
|
|
#[cfg_attr(flash_h7, path = "h7.rs")]
|
2023-08-18 22:10:13 +02:00
|
|
|
#[cfg_attr(flash_h7ab, path = "h7.rs")]
|
2023-03-30 06:01:56 +02:00
|
|
|
#[cfg_attr(
|
|
|
|
not(any(
|
2023-08-18 22:10:13 +02:00
|
|
|
flash_l0, flash_l1, flash_l4, flash_wl, flash_wb, flash_f0, flash_f3, flash_f4, flash_f7, flash_g0, flash_h7,
|
|
|
|
flash_h7ab
|
2023-03-30 06:01:56 +02:00
|
|
|
)),
|
|
|
|
path = "other.rs"
|
|
|
|
)]
|
2022-05-02 15:36:02 +02:00
|
|
|
mod family;
|
2023-03-29 13:57:33 +02:00
|
|
|
|
2023-03-30 05:27:57 +02:00
|
|
|
#[allow(unused_imports)]
|
|
|
|
pub use family::*;
|
2023-03-25 17:00:52 +01:00
|
|
|
|
2022-04-20 13:49:59 +02:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
|
pub enum Error {
|
|
|
|
Prog,
|
|
|
|
Size,
|
|
|
|
Miss,
|
|
|
|
Seq,
|
|
|
|
Protected,
|
|
|
|
Unaligned,
|
2022-05-03 16:16:37 +02:00
|
|
|
Parallelism,
|
2022-04-20 13:49:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl NorFlashError for Error {
|
|
|
|
fn kind(&self) -> NorFlashErrorKind {
|
|
|
|
match self {
|
|
|
|
Self::Size => NorFlashErrorKind::OutOfBounds,
|
|
|
|
Self::Unaligned => NorFlashErrorKind::NotAligned,
|
|
|
|
_ => NorFlashErrorKind::Other,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|