{"record":{"id":"c4bc501db180046c","repo":"embassy-rs/embassy","slug":"embassy-is-configured-as-single-bank-but-the-hard-c4bc50","errorCode":null,"errorMessage":"Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config","messagePattern":"Embassy is configured as single-bank, but the hardware is running in dual-bank mode\\. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/flash/g.rs","lineNumber":256,"sourceCode":"    if DATA_CACHE_WAS_ENABLED.load(Ordering::Relaxed) {\n        // Reset data cache before re-enabling\n        pac::FLASH.acr().modify(|w| w.set_dcrst(true));\n        pac::FLASH.acr().modify(|w| w.set_dcrst(false));\n        pac::FLASH.acr().modify(|w| w.set_dcen(true));\n    }\n}\n\n// G0 doesn't have data cache, use no-op functions\n#[cfg(any(flash_g0x0, flash_g0x1))]\nfn save_data_cache_state() {}\n\n#[cfg(any(flash_g0x0, flash_g0x1))]\nfn restore_data_cache_state() {}\n\n#[cfg(all(bank_setup_configurable, any(flash_g4c2, flash_g4c3, flash_g4c4)))]\npub(crate) fn check_bank_setup() {\n    if cfg!(feature = \"single-bank\") && pac::FLASH.optr().read().dbank() {\n        panic!(\n            \"Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use dual-bank config\"\n        );\n    }\n    if cfg!(feature = \"dual-bank\") && !pac::FLASH.optr().read().dbank() {\n        panic!(\n            \"Embassy is configured as dual-bank, but the hardware is running in single-bank mode. Change the hardware by changing the dbank value in the user option bytes or configure embassy to use single-bank config\"\n        );\n    }\n}\n\n#[cfg(all(bank_setup_configurable, flash_g0x1))]\npub(crate) fn check_bank_setup() {\n    if cfg!(feature = \"single-bank\") && pac::FLASH.optr().read().dual_bank() {\n        panic!(\n            \"Embassy is configured as single-bank, but the hardware is running in dual-bank mode. Change the hardware by changing the dual_bank value in the user option bytes or configure embassy to use dual-bank config\"\n        );\n    }\n    if cfg!(feature = \"dual-bank\") && !pac::FLASH.optr().read().dual_bank() {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/flash/g.rs#L238-L274","documentation":"On STM32G4 (and configurable G0) parts, the DBANK option bit selects dual-bank mode. Embassy built with 'single-bank' but with hardware DBANK=1 (dual) would compute wrong flash addresses, so check_bank_setup() panics at initialization. The panic names the exact option byte (dbank) to fix.","triggerScenarios":"Flash init on G4 (c2/c3/c4 variants) built with feature = \"single-bank\" while FLASH.optr.DBANK == 1.","commonSituations":"G4 boards shipped with dual-bank option bytes while firmware built single-bank for simpler sector sizes; after factory reset of option bytes; feature flag toggled for a different board and reused.","solutions":["Rebuild with the 'dual-bank' feature, or clear the DBANK option bit (STM32CubeProgrammer, then power cycle) to put the chip in single-bank mode.","Match the feature flag to the bank count your flash layout (partitions/bootloader) assumes.","Verify after any option-byte erase/reset that firmware features still match."],"exampleFix":"// before (Cargo.toml, G4 hardware dual-bank)\nfeatures = [\"stm32g474re\", \"single-bank\"]\n// after\nfeatures = [\"stm32g474re\", \"dual-bank\"]\n// or clear DBANK option byte and power cycle","handlingStrategy":"validation","validationCode":"fn g4_bank_ok(single_bank_feature: bool, dbank: bool) -> bool {\n    single_bank_feature == !dbank // DBANK=1 means dual bank\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check DBANK option bit on G4 boards before choosing flash features","Avoid resetting option bytes to defaults if firmware expects single-bank","Match DBANK with your partition/bootloader layout requirements"],"tags":["rust","embassy","embedded","stm32","flash","build-configuration"],"backgroundTag":"invalid-config-value","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"}