{"record":{"id":"5bc5b3f72e1edc73","repo":"embassy-rs/embassy","slug":"invalid-word-size-5bc5b3","errorCode":null,"errorMessage":"invalid word size","messagePattern":"invalid word size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/dma/dma_bdma.rs","lineNumber":559,"sourceCode":"                };\n\n                // NDTR is the number of transfers in the *peripheral* word size.\n                // ex: if mem_size=1, peri_size=4 and ndtr=3 it'll do 12 mem transfers, 3 peri transfers.\n                let ndtr = match (mem_size, peri_size) {\n                    (WordSize::FourBytes, WordSize::OneByte) => mem_len * 4,\n                    (WordSize::FourBytes, WordSize::TwoBytes) | (WordSize::TwoBytes, WordSize::OneByte) => mem_len * 2,\n                    (WordSize::FourBytes, WordSize::FourBytes)\n                    | (WordSize::TwoBytes, WordSize::TwoBytes)\n                    | (WordSize::OneByte, WordSize::OneByte) => mem_len,\n                    (WordSize::TwoBytes, WordSize::FourBytes) | (WordSize::OneByte, WordSize::TwoBytes) => {\n                        assert!(mem_len % 2 == 0);\n                        mem_len / 2\n                    }\n                    (WordSize::OneByte, WordSize::FourBytes) => {\n                        assert!(mem_len % 4 == 0);\n                        mem_len / 4\n                    }\n                    (WordSize::EightBytes, _) | (_, WordSize::EightBytes) => unimplemented!(\"invalid word size\"),\n                };\n\n                assert!(ndtr > 0 && ndtr <= 0xFFFF);\n\n                ch.par().write_value(peri_addr as u32);\n                ch.m0ar().write_value(mem_addr as u32);\n                ch.ndtr().write_value(pac::dma::regs::Ndtr(ndtr as _));\n                ch.fcr().write(|w| {\n                    if let Some(fth) = options.fifo_threshold {\n                        // FIFO mode\n                        w.set_dmdis(pac::dma::vals::Dmdis::Disabled);\n                        w.set_fth(fth.into());\n                    } else if mem_size != peri_size {\n                        // force FIFO mode if msize != psize\n                        // packing/unpacking doesn't work in direct mode.\n                        w.set_dmdis(pac::dma::vals::Dmdis::Disabled);\n                        w.set_fth(FifoThreshold::Half.into());\n                    } else {","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/dma/dma_bdma.rs#L541-L577","documentation":"In bDMA channel configuration, the NDTR (number of data to transfer) computation panics when either the memory or peripheral side uses WordSize::EightBytes, which this hardware path does not implement. The library throws it early in configure() rather than programming a wrong word-size field. It signals the requested transfer width is invalid for this DMA instance.","triggerScenarios":"Calling channel.configure()/start with mem or peri word size of EightBytes (e.g. &[u64] buffer); the match arm (WordSize::EightBytes, _) | (_, WordSize::EightBytes) is hit.","commonSituations":"DMA-ing arrays of f64/u64 samples; generic driver code instantiated with a 64-bit word type; buffer alignment mistakes leading a caller to pick the largest word size.","solutions":["Reconfigure the transfer with OneByte, TwoBytes or FourBytes word sizes on both sides","Convert the u64 buffer to a u32 (or smaller) buffer before the transfer","Verify the mem_len alignment assertion matches the chosen word size (mem_len % word_bytes == 0)","Update the driver's match arms if the target chip's bDMA actually supports 64-bit sizes"],"exampleFix":"// before\nlet wsize = WordSize::EightBytes;\nch.configure(None, peri_addr, &mem_buf, ..., wsize, ...);\n// after\nlet wsize = WordSize::FourBytes;\nch.configure(None, peri_addr, &mem_buf32, ..., wsize, ...);","handlingStrategy":"validation","validationCode":"fn check_transfer(mem: &[u32], peri_ws: WordSize) {\n    assert!(!matches!(peri_ws, WordSize::EightBytes));\n    assert!(mem.len() > 0 && mem.len() <= 0xFFFF);\n}","typeGuard":"fn is_valid_word_size(ws: WordSize) -> bool {\n    !matches!(ws, WordSize::EightBytes)\n}","tryCatchPattern":"if !is_valid_word_size(ws) {\n    return Err(Err::WordSizeUnsupported);\n}\nch.configure(..., ws, ...);","preventionTips":["Never configure EightBytes on bDMA channels","Ensure buffer length is a multiple of the word size and <= 0xFFFF","Assert word sizes at config wrapper level","Document word-size limits in your driver wrappers"],"tags":["embedded","dma","stm32","word-size","unimplemented"],"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"}