{"record":{"id":"83d9e76cbd3586d9","repo":"embassy-rs/embassy","slug":"cannot-select-usbphyc-reference-clock-with-source","errorCode":null,"errorMessage":"cannot select USBPHYC reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz","messagePattern":"cannot select USBPHYC reference clock with source frequency of (.+?), must be one of 16, 19\\.2, 20, 24, 26, 32 MHz","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/rcc/h.rs","lineNumber":659,"sourceCode":"    let rtc = config.ls.init();\n\n    #[cfg(all(stm32h7rs, peri_usb_otg_hs))]\n    let usb_refck = match config.mux.usbphycsel {\n        Usbphycsel::Hse => hse,\n        Usbphycsel::HseDiv2 => hse.map(|hse_val| hse_val / 2u8),\n        Usbphycsel::Pll3Q => pll3.q,\n        _ => None,\n    };\n    #[cfg(all(stm32h7rs, peri_usb_otg_hs))]\n    let usb_refck_sel = match usb_refck {\n        Some(clk_val) => match clk_val {\n            Hertz(16_000_000) => Usbrefcksel::Mhz16,\n            Hertz(19_200_000) => Usbrefcksel::Mhz192,\n            Hertz(20_000_000) => Usbrefcksel::Mhz20,\n            Hertz(24_000_000) => Usbrefcksel::Mhz24,\n            Hertz(26_000_000) => Usbrefcksel::Mhz26,\n            Hertz(32_000_000) => Usbrefcksel::Mhz32,\n            _ => panic!(\n                \"cannot select USBPHYC reference clock with source frequency of {}, must be one of 16, 19.2, 20, 24, 26, 32 MHz\",\n                clk_val\n            ),\n        },\n        None => Usbrefcksel::Mhz24,\n    };\n\n    #[cfg(stm32h7)]\n    {\n        RCC.d1cfgr().modify(|w| {\n            w.set_d1cpre(config.d1c_pre);\n            w.set_d1ppre(config.apb3_pre);\n            w.set_hpre(config.ahb_pre);\n        });\n        // Ensure core prescaler value is valid before future lower core voltage\n        while RCC.d1cfgr().read().d1cpre() != config.d1c_pre {}\n\n        RCC.d2cfgr().modify(|w| {","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/rcc/h.rs#L641-L677","documentation":"On H7RS (USBPHYC), the USB PHY reference clock selection register can only encode a fixed set of input frequencies: 16, 19.2, 20, 24, 26 or 32 MHz. init panics if the selected USBPHYC reference source frequency (clk_val) is anything else; when no source is configured the driver defaults to Mhz24.","triggerScenarios":"Configuring the USB PHY reference clock on stm32h7rs with a source crystal/PLL output whose frequency is not exactly one of 16, 19.2, 20, 24, 26 or 32 MHz (e.g. 8 MHz, 25 MHz, 48 MHz), so the match arm falls through to the panic.","commonSituations":"Board crystals that do not match the PHY's supported list; reusing an H7 (non-RS) clock config on H7RS; assuming any frequency can be divided down automatically — the driver does not add extra dividers.","solutions":["Choose a PLL output or crystal for the USBPHYC reference that is exactly 16, 19.2, 20, 24, 26 or 32 MHz.","Adjust upstream PLL dividers so the derived reference lands exactly on one of the supported values.","If no explicit source is needed, leave it unset to use the default 24 MHz selection."],"exampleFix":"// before\n// usb refck source = 25 MHz crystal -> panic\n// after\n// derive 20 MHz from PLL via divider and use it as usb refck source:\n// Usbrefcksel::Mhz20 (freq = 20_000_000.Hz())","handlingStrategy":"validation","validationCode":"const USBPHYC_REF: [u32; 6] = [16_000_000, 19_200_000, 20_000_000, 24_000_000, 26_000_000, 32_000_000];\nif let Some(f) = usb_refck_source {\n    assert!(USBPHYC_REF.contains(&f.0), \"USBPHYC ref {} Hz not supported\", f.0);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick crystals/PLL outputs for the PHY reference from the supported 6-value list only.","Compute upstream dividers so the derived frequency lands exactly on a supported value (integer match, not approximately).","Leave the source unset to accept the 24 MHz default when flexibility exists."],"tags":["rust","embedded","rcc","usb","stm32h7rs"],"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"}