{"record":{"id":"3f2f25667e3884c1","repo":"embassy-rs/embassy","slug":"partition-offset-must-be-a-multiple-of-read-write","errorCode":null,"errorMessage":"Partition offset must be a multiple of read, write and erase size","messagePattern":"Partition offset must be a multiple of read, write and erase size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-embedded-hal/src/flash/partition/asynch.rs","lineNumber":36,"sourceCode":"    size: u32,\n}\n\nimpl<'a, M: RawMutex, T: NorFlash> Clone for Partition<'a, M, T> {\n    fn clone(&self) -> Self {\n        Self {\n            flash: self.flash,\n            offset: self.offset,\n            size: self.size,\n        }\n    }\n}\n\nimpl<'a, M: RawMutex, T: NorFlash> Partition<'a, M, T> {\n    /// Create a new partition\n    pub const fn new(flash: &'a Mutex<M, T>, offset: u32, size: u32) -> Self {\n        if offset % T::READ_SIZE as u32 != 0 || offset % T::WRITE_SIZE as u32 != 0 || offset % T::ERASE_SIZE as u32 != 0\n        {\n            panic!(\"Partition offset must be a multiple of read, write and erase size\");\n        }\n        if size % T::READ_SIZE as u32 != 0 || size % T::WRITE_SIZE as u32 != 0 || size % T::ERASE_SIZE as u32 != 0 {\n            panic!(\"Partition size must be a multiple of read, write and erase size\");\n        }\n        Self { flash, offset, size }\n    }\n\n    /// Get the partition offset within the flash\n    pub const fn offset(&self) -> u32 {\n        self.offset\n    }\n\n    /// Get the partition size\n    pub const fn size(&self) -> u32 {\n        self.size\n    }\n}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-embedded-hal/src/flash/partition/asynch.rs#L18-L54","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Round the offset up to a multiple of the flash's ERASE_SIZE (usually the largest constraint)","Define partitions as sector counts and multiply by ERASE_SIZE instead of raw byte offsets","Check T::READ_SIZE/WRITE_SIZE/ERASE_SIZE and assert alignment in your layout definitions","Regenerate the partition layout for the actual flash chip in use"],"exampleFix":"// before\nlet part = Partition::new(&flash, 1024 * 3, 64 * 1024); // 3072 not multiple of 4096\n// after\nlet part = Partition::new(&flash, 4096, 64 * 1024); // aligned to ERASE_SIZE","handlingStrategy":"validation","validationCode":"const fn offset_aligned<T: NorFlash>(offset: u32) -> bool {\n    offset % T::READ_SIZE as u32 == 0\n        && offset % T::WRITE_SIZE as u32 == 0\n        && offset % T::ERASE_SIZE as u32 == 0\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Express partition offsets as multiples of ERASE_SIZE, never raw bytes","Keep one shared layout module that computes offsets from sector counts","Re-derive offsets whenever the underlying flash changes","Prefer sector-aligned round numbers when documenting the memory map"],"tags":["embedded","flash","partition","panic","alignment"],"backgroundTag":"invalid-argument-value","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}