embassy-rs/embassy · error
attempted to use peripheral
Error message
attempted to use peripheral '{}' but its clock mux is not set to a valid clock. Change 'config.rcc.mux' to another clock. What it means
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.
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.
Example fix
// before let mut config = Config::default(); // mux never set let mut adc = Adc::new(p.ADC1); // after let mut config = Config::default(); config.rcc.mux.adc12sel = embassy_stm32::rcc::mux::Adc12sel::SYS; let mut adc = Adc::new(p.ADC1);
Defensive patterns
Strategy: validation
Validate before calling
// set the mux in Config before creating the peripheral: let mut config = Config::default(); config.rcc.mux.adc12sel = embassy_stm32::rcc::mux::Adc12sel::SYS;
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Bank 1 not present
- Bank 2 not present
- OTP not present
- The LCD driver needs the RTC/LCD clock to be running
- if PLL source is HSI, PLL prediv must be 2.
AI-assisted analysis of embassy-rs/embassy@463a07b963 (2026-09-10).
Data as JSON: /api/errors/75dd8104bdd70e50.
Report an issue: GitHub.
Appendix: source
Thrown at embassy-stm32/build.rs:875
for v in enumm.variants.iter().filter(|v| v.name != "Disable") {
let variant_name = format_ident!("{}", v.name);
let upper_snake = pascal_to_upper_snake(v.name);
let expr = if let Some(mux) = self.chained_muxes.get(upper_snake.as_str()) {
self.gen_mux(peripheral, mux)
} else {
self.gen_clock(peripheral, &upper_snake)
};
match_arms.extend(quote! {
crate::pac::rcc::vals::#enum_name::#variant_name => #expr,
});
}
quote! {
match crate::pac::RCC.#fieldset_name().read().#field_name() {
#match_arms
#[allow(unreachable_patterns)]
_ => panic!(
"attempted to use peripheral '{}' but its clock mux is not set to a valid \
clock. Change 'config.rcc.mux' to another clock.",
#peripheral
)
}
}
}
}
let mut refcount_idxs = BTreeSet::new();
for p in METADATA.peripherals {
if !singletons.contains(&p.name.to_string()) {
continue;
}
if let Some(rcc) = &p.rcc {
let rst_reg = rcc.reset.as_ref();View on GitHub (pinned to 463a07b963)