Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions esp-storage/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ impl<'d> Flash<'d> {
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
/// Flash storage abstraction.
///
/// This can write to any location on the SPI Flash.
/// It is recommended to create a
#[doc = concat!("[partition](https://docs.espressif.com/projects/esp-idf/en/latest/", esp_hal::chip!(), "/api-guides/partition-tables.html)")]
/// to store any app data.
pub struct FlashStorage<'d> {
pub(crate) capacity: usize,
unlocked: bool,
Expand Down
23 changes: 23 additions & 0 deletions esp-storage/src/nor_flash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ impl NorFlash for FlashStorage<'_> {
const WRITE_SIZE: usize = Self::WORD_SIZE as _;
const ERASE_SIZE: usize = Self::SECTOR_SIZE as _;

/// Writes `bytes` to the flash storage at `offset`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation is inherited from traits. I think if the trait's docs are insufficient, this should be sent to embedded-storage instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidently, clearing up embedded-storage documentation could help close #4094

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even so, since we are overriding the trait method's documentation I believe a short synopsis is justified for convenience (and because docsrs shows the first line as a short description).
Perhaps a better idea would to put this documentation on the struct and improve the embedded-storage docs?

///
/// Note that NOR flash is only able to flip bits from 1 to 0. Attempting to
/// flip a bit from 0 to 1 will silently fail. It may be necessary to call
/// [`FlashStorage::erase`] before writing to ensure all bits being written
/// to are 1.
///
/// Requirements:
/// - `offset` must be aligned to a word (4 bytes).
/// - `bytes.len()` must be a multiple of the word size.
///
/// Requirements not being met will lead to an error.
///
/// See [`NorFlash::write`] for more information.
fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
const WS: u32 = FlashStorage::WORD_SIZE;
self.check_alignment::<{ WS }>(offset, bytes.len())?;
Expand Down Expand Up @@ -174,6 +188,15 @@ impl NorFlash for FlashStorage<'_> {
Ok(())
}

/// Erases sectors at bytes `[from..to]`
///
/// Requirements:
/// - `from` must be aligned to a sector (4096 bytes).
/// - `to - from` must be a multiple of the sector size.
///
/// Requirements not being met will lead to an error.
///
/// See [`NorFlash::erase`] for more information.
fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
let len = (to - from) as _;
const SZ: u32 = FlashStorage::SECTOR_SIZE;
Expand Down
Loading