{"record":{"id":"8b421bc278bb9429","repo":"embassy-rs/embassy","slug":"qspi-address-too-large-to-be-represented-with-the","errorCode":null,"errorMessage":"QSPI address too large to be represented with the given address size","messagePattern":"QSPI address too large to be represented with the given address size","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/qspi/mod.rs","lineNumber":375,"sourceCode":"    }\n\n    fn setup_command(&mut self, transaction: TransferConfig) {\n        #[cfg(not(stm32h7))]\n        T::REGS.cr().modify(|v| v.set_dmaen(false));\n\n        self.setup_transaction(QspiMode::IndirectWrite, &transaction, None);\n    }\n\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);","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/qspi/mod.rs#L357-L393","documentation":"The address value supplied needs more bits than transaction.address_size declares (8, 16, 24, or 32 bits), so it cannot be transmitted within that address size field. The library panics to prevent silent truncation of the address on the bus.","triggerScenarios":"Passing an address >= 2^address_size bits, e.g. Some(0x01FF_FFFF) with AddressSize::_24Bit, through blocking_read/blocking_write/setup_auto_poll/setup_command.","commonSituations":"Using 24-bit addressing with a flash device whose capacity requires 32-bit (4-byte) addresses; overflowing byte-offset math when addressing beyond 16 MB; reusing a fixed AddressSize across differently sized flash chips.","solutions":["Increase transaction.address_size (e.g. AddressSize::_32Bit) to fit the address value.","Compute the address within the declared size, or derive address_size from the device's addressing mode (3-byte vs 4-byte command set)."],"exampleFix":"// before\nlet t = TransferConfig::new(cmd, QspiWidth::SING, Some(0x0200_0000), QspiWidth::SING, QspiWidth::SING).with_address_size(AddressSize::_24Bit);\n// after\nlet t = TransferConfig::new(cmd, QspiWidth::SING, Some(0x0200_0000), QspiWidth::SING, QspiWidth::SING).with_address_size(AddressSize::_32Bit);","handlingStrategy":"validation","validationCode":"fn address_fits_size(address: u32, size: AddressSize) -> bool {\n    (u32::BITS - address.leading_zeros()) as usize <= size.bit_width()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick address_size from the flash device's addressing mode (3- vs 4-byte).","Add an assert when building configs with large addresses.","Watch for offset overflow when addressing >16 MB with 24-bit sizes."],"tags":["rust","embedded","stm32","qspi","overflow","validation"],"backgroundTag":"value-out-of-range","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"}