{"record":{"id":"75dd8104bdd70e50","repo":"embassy-rs/embassy","slug":"attempted-to-use-peripheral-but-its-clock-mux","errorCode":null,"errorMessage":"attempted to use peripheral '{}' but its clock mux is not set to a valid clock. Change 'config.rcc.mux' to another clock.","messagePattern":"attempted to use peripheral '(.+?)' but its clock mux is not set to a valid clock\\. Change 'config\\.rcc\\.mux' to another clock\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/build.rs","lineNumber":875,"sourceCode":"\n            for v in enumm.variants.iter().filter(|v| v.name != \"Disable\") {\n                let variant_name = format_ident!(\"{}\", v.name);\n                let upper_snake = pascal_to_upper_snake(v.name);\n                let expr = if let Some(mux) = self.chained_muxes.get(upper_snake.as_str()) {\n                    self.gen_mux(peripheral, mux)\n                } else {\n                    self.gen_clock(peripheral, &upper_snake)\n                };\n                match_arms.extend(quote! {\n                    crate::pac::rcc::vals::#enum_name::#variant_name => #expr,\n                });\n            }\n\n            quote! {\n                match crate::pac::RCC.#fieldset_name().read().#field_name() {\n                    #match_arms\n                    #[allow(unreachable_patterns)]\n                    _ => panic!(\n                        \"attempted to use peripheral '{}' but its clock mux is not set to a valid \\\n                         clock. Change 'config.rcc.mux' to another clock.\",\n                        #peripheral\n                    )\n                }\n            }\n        }\n    }\n\n    let mut refcount_idxs = BTreeSet::new();\n\n    for p in METADATA.peripherals {\n        if !singletons.contains(&p.name.to_string()) {\n            continue;\n        }\n\n        if let Some(rcc) = &p.rcc {\n            let rst_reg = rcc.reset.as_ref();","sourceCodeStart":857,"sourceCodeEnd":893,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/build.rs#L857-L893","documentation":"embassy-stm32 generates a match on the RCC clock-mux register field for each peripheral requiring a selected clock source; the wildcard arm panics with the peripheral name when the mux value is neither a known clock nor a recognized encoding. This is a runtime panic meaning the RCC mux register holds an invalid value, or the mux was never set to a valid source before the peripheral was used.","triggerScenarios":"Using a peripheral whose RCC clock-mux register field holds an invalid/reserved value at runtime — the generated `match RCC.#fieldset().read().#field()` falls through to the wildcard `_ =>` panic arm.","commonSituations":"Modifying RCC mux registers manually (unsafe writes) before using the peripheral; clock configuration applied by a bootloader that leaves an unrecognized mux encoding; missing `config.rcc.mux` entries.","solutions":["Set the peripheral's clock mux explicitly via embassy's config: `config.rcc.mux.<xxxsel> = val` before using the peripheral.","Don't hand-write to RCC mux registers outside embassy's RCC setup.","If a bootloader changed clocking, reset the mux or re-run embassy's RCC init before peripheral use."],"exampleFix":"// before\nlet mut config = Config::default(); // mux never set\nlet mut adc = Adc::new(p.ADC1);\n// after\nlet mut config = Config::default();\nconfig.rcc.mux.adc12sel = embassy_stm32::rcc::mux::Adc12sel::SYS;\nlet mut adc = Adc::new(p.ADC1);","handlingStrategy":"validation","validationCode":"// set the mux in Config before creating the peripheral:\nlet mut config = Config::default();\nconfig.rcc.mux.adc12sel = embassy_stm32::rcc::mux::Adc12sel::SYS;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always configure rcc.mux entries for peripherals that require a clock source selection.","Avoid raw RCC register writes outside embassy's RCC init.","Reset RCC state when a bootloader may have altered clock muxes."],"tags":["rcc","clock-mux","stm32","runtime-panic"],"backgroundTag":"invalid-enum-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"}