{"record":{"id":"6f75aa496af8f213","repo":"embassy-rs/embassy","slug":"must-not-select-pll-source-as-disable-6f75aa","errorCode":null,"errorMessage":"must not select PLL source as DISABLE","messagePattern":"must not select PLL source as DISABLE","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/rcc/u5.rs","lineNumber":617,"sourceCode":"enum PllInstance {\n    Pll1 = 0,\n    Pll2 = 1,\n    Pll3 = 2,\n}\n\nfn pll_enable(instance: PllInstance, enabled: bool) {\n    RCC.cr().modify(|w| w.set_pllon(instance as _, enabled));\n    while RCC.cr().read().pllrdy(instance as _) != enabled {}\n}\n\nfn init_pll(instance: PllInstance, config: Option<Pll>, input: &PllInput, voltage_range: VoltageScale) -> PllOutput {\n    // Disable PLL\n    pll_enable(instance, false);\n\n    let Some(pll) = config else { return PllOutput::default() };\n\n    let src_freq = match pll.source {\n        PllSource::Disable => panic!(\"must not select PLL source as DISABLE\"),\n        PllSource::Hse => unwrap!(input.hse),\n        PllSource::Hsi => unwrap!(input.hsi),\n        PllSource::Msis => unwrap!(input.msi),\n    };\n\n    // Calculate the reference clock, which is the source divided by m\n    let ref_freq = src_freq / pll.prediv;\n    // Check limits per RM0456 § 11.4.6\n    assert!(Hertz::mhz(4) <= ref_freq && ref_freq <= Hertz::mhz(16));\n\n    // Check PLL clocks per RM0456 § 11.4.10\n    let (vco_min, vco_max, out_max) = match voltage_range {\n        VoltageScale::Range1 => (Hertz::mhz(128), Hertz::mhz(544), Hertz::mhz(208)),\n        VoltageScale::Range2 => (Hertz::mhz(128), Hertz::mhz(544), Hertz::mhz(110)),\n        VoltageScale::Range3 => (Hertz::mhz(128), Hertz::mhz(330), Hertz::mhz(55)),\n        VoltageScale::Range4 => panic!(\"PLL is unavailable in voltage range 4\"),\n    };\n","sourceCodeStart":599,"sourceCodeEnd":635,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/rcc/u5.rs#L599-L635","documentation":"embassy-stm32's STM32U5 init_pll panics if the PLL configuration's source is PllSource::Disable. init_pll is only reached when a PLL config is actually present; selecting Disable as the source is contradictory — to disable the PLL you must pass None for the whole PLL config, not a PLL config with a Disabled source.","triggerScenarios":"Setting pll.source = PllSource::Disable while still supplying the Some(pll_config) to init_pll via rcc init (e.g. leaving a copied config's source field at its Disable default).","commonSituations":"Copying an RCC config where only source was reset to Disable; scaffolding a new PLL config from an enum and forgetting to pick Hse/Hsi/Msis; refactoring code and nulling the source instead of the whole PLL option.","solutions":["Set pll.source to PllSource::Hse, PllSource::Hsi, or PllSource::Msis (and ensure that clock is configured so input.hse/hsi/msi is Some)","If you intend no PLL, pass None for the PLL config instead of a config with a Disable source"],"exampleFix":"// before\nlet pll = Some(PllConfig { source: PllSource::Disable, m: 1, n: 40, divp: ..., ... });\n// after\nlet pll = Some(PllConfig { source: PllSource::Hsi, m: 1, n: 40, divp: ..., ... });\n// or to disable the PLL entirely:\nlet pll = None;","handlingStrategy":"validation","validationCode":"if let Some(pll) = &config.pll1 {\n    assert!(pll.source != PllSource::Disable, \"set a real PLL source or pass None\");\n}","typeGuard":"fn pll_configured(pll: &Option<PllConfig>) -> bool {\n    matches!(pll, Some(p) if p.source != PllSource::Disable)\n}","tryCatchPattern":null,"preventionTips":["To disable a PLL, pass None for its config, never PllSource::Disable inside Some","Pick Hse/Hsi/Msis explicitly and ensure that clock is initialized","Avoid leaving scaffolding enum variants in shipped configs","Copy complete PLL configs, not partially reset ones"],"tags":["rust","embedded","stm32","rcc","pll","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"}