{"record":{"id":"962112a2e570a2ee","repo":"embassy-rs/embassy","slug":"qspi-data-must-be-at-least-one-byte","errorCode":null,"errorMessage":"QSPI data must be at least one byte","messagePattern":"QSPI data must be at least one byte","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/qspi/mod.rs","lineNumber":383,"sourceCode":"\n    fn setup_transaction(&mut self, fmode: QspiMode, transaction: &TransferConfig, data_len: Option<usize>) {\n        self.assert_transfer_widths(transaction);\n\n        match (transaction.address, transaction.awidth) {\n            (Some(_), QspiWidth::NONE) => panic!(\"QSPI address can't be sent with an address width of NONE\"),\n            (Some(address), _) => {\n                // u32::bit_width was only stabilized in 1.97\n                let address_bit_width = u32::BITS - address.leading_zeros();\n                if address_bit_width > transaction.address_size.bit_width() as u32 {\n                    panic!(\"QSPI address too large to be represented with the given address size\");\n                }\n            }\n            (None, QspiWidth::NONE) => {}\n            (None, _) => panic!(\"QSPI address is not set, so the address width should be NONE\"),\n        }\n\n        match (data_len, transaction.dwidth) {\n            (Some(0), _) => panic!(\"QSPI data must be at least one byte\"),\n            (Some(_), QspiWidth::NONE) => panic!(\"QSPI data can't be sent with a data width of NONE\"),\n            (Some(_), _) => {}\n            (None, QspiWidth::NONE) => {}\n            (None, _) => panic!(\"QSPI data is empty, so the data width should be NONE\"),\n        }\n\n        T::REGS.fcr().modify(|v| {\n            v.set_csmf(true);\n            v.set_ctcf(true);\n            v.set_ctef(true);\n            v.set_ctof(true);\n        });\n\n        while T::REGS.sr().read().busy() {}\n\n        if let Some(len) = data_len {\n            T::REGS.dlr().write(|v| v.set_dl(len as u32 - 1));\n        }","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/qspi/mod.rs#L365-L401","documentation":"A data length of exactly 0 bytes was requested with a data transfer. The QSPI transaction machinery cannot express a zero-length data phase meaningfully, so the library treats it as a configuration mistake and panics.","triggerScenarios":"Calling blocking_read/blocking_write (or a transaction routed through setup_transaction) with data_len = Some(0), e.g. an empty write buffer or a computed length of zero.","commonSituations":"Slicing an empty buffer for a write; a size/len computation that returns 0 (e.g. reading 0 bytes of a register); generic code that forwards buffer.len() without checking for empty buffers.","solutions":["Issue the transaction without a data phase (data_len = None, dwidth = QspiWidth::NONE) for command/address-only operations.","Guard the call: skip or early-return when the buffer is empty.","Fix the length computation so at least one byte is requested when data transfer is intended."],"exampleFix":"// before\nif buf.is_empty() { /* still issues transaction */ }\nqspi.blocking_read(addr, &mut buf[..0]);\n// after\nif buf.is_empty() { return Ok(()); } // or send a command-only transaction\nqspi.blocking_read(addr, &mut buf);","handlingStrategy":"validation","validationCode":"fn data_phase_ok(len: Option<usize>, w: QspiWidth) -> bool {\n    match (len, w) {\n        (Some(0), _) => false,\n        (Some(_), QspiWidth::NONE) => false,\n        (None, w) => w == QspiWidth::NONE,\n        _ => true,\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Early-return on empty buffers before issuing data transactions.","Issue command-only transactions (data None / width NONE) instead of zero-length data."],"tags":["rust","embedded","stm32","qspi","validation","empty-buffer"],"backgroundTag":"empty-required-field","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"}