embassy-rs/embassy · error

Partition offset must be a multiple of read, write and…

Error message

Partition offset must be a multiple of read, write and erase size

What it means

`Partition::new` (async variant in embassy-embedded-hal) validates at construction time that the partition offset is a multiple of the underlying flash's READ_SIZE, WRITE_SIZE and ERASE_SIZE. A misaligned offset would make partition-relative addresses unrepresentable in whole flash operations, so it panics in the const constructor.

Solutions

  1. Round the offset up to a multiple of the flash's ERASE_SIZE (usually the largest constraint)
  2. Define partitions as sector counts and multiply by ERASE_SIZE instead of raw byte offsets
  3. Check T::READ_SIZE/WRITE_SIZE/ERASE_SIZE and assert alignment in your layout definitions
  4. Regenerate the partition layout for the actual flash chip in use

Example fix

// before
let part = Partition::new(&flash, 1024 * 3, 64 * 1024); // 3072 not multiple of 4096
// after
let part = Partition::new(&flash, 4096, 64 * 1024); // aligned to ERASE_SIZE
Defensive patterns

Strategy: validation

Validate before calling

const fn offset_aligned<T: NorFlash>(offset: u32) -> bool {
    offset % T::READ_SIZE as u32 == 0
        && offset % T::WRITE_SIZE as u32 == 0
        && offset % T::ERASE_SIZE as u32 == 0
}

Prevention

When it happens

Trigger: Calling `Partition::new(&mutex_flash, offset, size)` where `offset % T::READ_SIZE != 0`, `offset % T::WRITE_SIZE != 0`, or `offset % T::ERASE_SIZE != 0` — e.g. offset 1024 on a flash with ERASE_SIZE 4096.

Common situations: Hand-picking partition boundaries in bytes that look 'nice' but ignore sector alignment; layouts from a different chip reused on a flash with larger erase sectors; accumulating sizes (e.g. 3 KiB slots) that are not sector multiples.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of embassy-rs/embassy@463a07b963 (2026-09-10). Data as JSON: /api/errors/3f2f25667e3884c1. Report an issue: GitHub.

Appendix: source

Thrown at embassy-embedded-hal/src/flash/partition/asynch.rs:36

    size: u32,
}

impl<'a, M: RawMutex, T: NorFlash> Clone for Partition<'a, M, T> {
    fn clone(&self) -> Self {
        Self {
            flash: self.flash,
            offset: self.offset,
            size: self.size,
        }
    }
}

impl<'a, M: RawMutex, T: NorFlash> Partition<'a, M, T> {
    /// Create a new partition
    pub const fn new(flash: &'a Mutex<M, T>, offset: u32, size: u32) -> Self {
        if offset % T::READ_SIZE as u32 != 0 || offset % T::WRITE_SIZE as u32 != 0 || offset % T::ERASE_SIZE as u32 != 0
        {
            panic!("Partition offset must be a multiple of read, write and erase size");
        }
        if size % T::READ_SIZE as u32 != 0 || size % T::WRITE_SIZE as u32 != 0 || size % T::ERASE_SIZE as u32 != 0 {
            panic!("Partition size must be a multiple of read, write and erase size");
        }
        Self { flash, offset, size }
    }

    /// Get the partition offset within the flash
    pub const fn offset(&self) -> u32 {
        self.offset
    }

    /// Get the partition size
    pub const fn size(&self) -> u32 {
        self.size
    }
}

View on GitHub (pinned to 463a07b963)