{"record":{"id":"2710ba4a3eebc9e8","repo":"embassy-rs/embassy","slug":"partition-size-must-be-a-multiple-of-read-write-a-2710ba","errorCode":null,"errorMessage":"Partition size must be a multiple of read, write and erase size","messagePattern":"Partition size 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/blocking.rs","lineNumber":40,"sourceCode":"impl<'a, M: RawMutex, T: NorFlash> Clone for BlockingPartition<'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> BlockingPartition<'a, M, T> {\n    /// Create a new partition\n    pub const fn new(flash: &'a Mutex<M, RefCell<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\nimpl<M: RawMutex, T: NorFlash> ErrorType for BlockingPartition<'_, M, T> {\n    type Error = Error<T::Error>;\n}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-embedded-hal/src/flash/partition/blocking.rs#L22-L58","documentation":"This is a compile-time const-evaluation panic in BlockingPartition::new: the partition bounds are rejected before any flash access can occur. It fires because the requested offset or size is not aligned to the underlying NorFlash's READ_SIZE, WRITE_SIZE or ERASE_SIZE, or (in the sibling check) the size itself is not a multiple of those alignment units. Flash hardware can only read, program and erase on these granularities, so a misaligned partition would cause undefined behavior or data corruption.","triggerScenarios":"Thrown at embassy-embedded-hal/src/flash/partition/blocking.rs:40 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Align the partition offset to a multiple of the flash's ERASE_SIZE (which is always a multiple of READ_SIZE and WRITE_SIZE)","Choose a partition size that is an exact multiple of the erase size so every sector fits wholly within the partition","Compute offset and size from the chip's geometry constants (e.g. 4096-byte sectors) instead of hardcoding arbitrary values","If a non-aligned region is genuinely needed, add a software layer that pads/rounds accesses to alignment boundaries rather than slicing the flash directly"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}