Skip to content

Commit c215ade

Browse files
committed
Improve FlashStorage documentation
1 parent b1aedf6 commit c215ade

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

esp-storage/src/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ impl<'d> Flash<'d> {
6666
#[derive(Debug)]
6767
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6868
/// Flash storage abstraction.
69+
///
70+
/// This can write to any location on the SPI Flash. It is recommended
71+
/// to create a [partition] to store any app data.
72+
///
73+
/// [partition]: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/partition-tables.html
6974
pub struct FlashStorage<'d> {
7075
pub(crate) capacity: usize,
7176
unlocked: bool,

esp-storage/src/nor_flash.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ impl NorFlash for FlashStorage<'_> {
140140
const WRITE_SIZE: usize = Self::WORD_SIZE as _;
141141
const ERASE_SIZE: usize = Self::SECTOR_SIZE as _;
142142

143+
/// Writes `bytes` to the flash storage at `offset`.
144+
///
145+
/// Requirements:
146+
/// - `offset` must be aligned to a word (4 bytes).
147+
/// - `bytes.len()` must be a multiple of the word size.
148+
/// - The bytes being written to must have been previously erased by [`FlashStorage::erase`].
149+
///
150+
/// Requirements not being met will lead to an error or incorrect data being written.
151+
///
152+
/// See [`NorFlash::write`] for more information.
143153
fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error> {
144154
const WS: u32 = FlashStorage::WORD_SIZE;
145155
self.check_alignment::<{ WS }>(offset, bytes.len())?;
@@ -174,6 +184,15 @@ impl NorFlash for FlashStorage<'_> {
174184
Ok(())
175185
}
176186

187+
/// Erases sectors at bytes `[from..to]`
188+
///
189+
/// Requirements:
190+
/// - `from` must be aligned to a sector (4096 bytes).
191+
/// - `to - from` must be a multiple of the sector size.
192+
///
193+
/// Requirements not being met will lead to an error.
194+
///
195+
/// See [`NorFlash::erase`] for more information.
177196
fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error> {
178197
let len = (to - from) as _;
179198
const SZ: u32 = FlashStorage::SECTOR_SIZE;

0 commit comments

Comments
 (0)