{"record":{"id":"92d8138f61abe47a","repo":"embassy-rs/embassy","slug":"invalid-word-size","errorCode":null,"errorMessage":"Invalid word size","messagePattern":"Invalid word size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/dma/gpdma/mod.rs","lineNumber":456,"sourceCode":"            packing: vals::Pam::Pack,\n\n            #[cfg(not(stm32c5))]\n            burst_length: Burst::_1Beats,\n            request_mode: RequestMode::Burst,\n            transfer_complete_mode: TransferCompleteMode::EachBlock,\n            trigger: None,\n        }\n    }\n}\n\n#[cfg(gpdma)]\nimpl From<WordSize> for pac::gpdma::vals::Dw {\n    fn from(raw: WordSize) -> Self {\n        match raw {\n            WordSize::OneByte => Self::Byte,\n            WordSize::TwoBytes => Self::HalfWord,\n            WordSize::FourBytes => Self::Word,\n            _ => panic!(\"Invalid word size\"),\n        }\n    }\n}\n\n#[cfg(gpdma)]\nimpl From<pac::gpdma::vals::Dw> for WordSize {\n    fn from(raw: pac::gpdma::vals::Dw) -> Self {\n        match raw {\n            pac::gpdma::vals::Dw::Byte => Self::OneByte,\n            pac::gpdma::vals::Dw::HalfWord => Self::TwoBytes,\n            pac::gpdma::vals::Dw::Word => Self::FourBytes,\n            _ => panic!(\"Invalid word size\"),\n        }\n    }\n}\n\n#[cfg(lpdma)]\nimpl From<WordSize> for pac::lpdma::vals::Dw {","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/dma/gpdma/mod.rs#L438-L474","documentation":"This From<WordSize> impl converts the crate's WordSize enum into the GPDMA hardware DW register value. WordSize has more variants than GPDMA supports (e.g. DoubleWord sizes on other DMA IP), and any such variant reaches a catch-all arm that panics.","triggerScenarios":"Converting a WordSize variant larger than FourBytes (e.g. WordSize::EightBytes / DoubleWord) into pac::gpdma::vals::Dw via .into() when configuring a GPDMA transfer.","commonSituations":"Generic transfer code that takes WordSize from a user or another driver where 8-byte words are legal on other STM32 DMA peripherals but not on GPDMA.","solutions":["Only use WordSize::OneByte, TwoBytes, or FourBytes with GPDMA transfers","Match on WordSize yourself before converting and return a proper error for unsupported sizes","Check the width requirements of the peripheral; shrink the transfer to a supported word size"],"exampleFix":"// before\nlet dw: pac::gpdma::vals::Dw = WordSize::EightBytes.into(); // panics\n// after\nlet ws = match req.word_size { WordSize::OneByte | WordSize::TwoBytes | WordSize::FourBytes => req.word_size, _ => panic!(\"gpdma supports at most 4-byte words\") };\nlet dw: pac::gpdma::vals::Dw = ws.into();","handlingStrategy":"validation","validationCode":"fn gpdma_word_ok(ws: WordSize) -> bool { matches!(ws, WordSize::OneByte | WordSize::TwoBytes | WordSize::FourBytes) }","typeGuard":"fn as_gpdma_word(ws: WordSize) -> Option<WordSize> { matches!(ws, WordSize::OneByte | WordSize::TwoBytes | WordSize::FourBytes).then_some(ws) }","tryCatchPattern":"// Panic-based conversion: check the variant before .into().\nlet dw = match ws { WordSize::OneByte | WordSize::TwoBytes | WordSize::FourBytes => ws.into(), _ => return Err(Error::InvalidWordSize) };","preventionTips":["Constrain word-size config to at most 4 bytes when targeting GPDMA","Check peripheral data-register width before choosing WordSize"],"tags":["rust","embedded","dma","panic","word-size"],"backgroundTag":"unsupported-dtype","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"}