{"record":{"id":"a3c9526dbbbbe731","repo":"embassy-rs/embassy","slug":"maximal-allowed-frequency-for-adc4-is-mhz-and-i","errorCode":null,"errorMessage":"Maximal allowed frequency for ADC4 is {} MHz and it varies with different packages, refer to ST docs for more information.","messagePattern":"Maximal allowed frequency for ADC4 is (.+?) MHz and it varies with different packages, refer to ST docs for more information\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/adc/adc4.rs","lineNumber":389,"sourceCode":"\n    fn wait_done(&self) -> bool {\n        self.isr().read().eos()\n    }\n}\n\nimpl<'d, T: Instance<Regs = crate::pac::adc::Adc4>> super::Adc<'d, T> {\n    /// Create a new ADC driver.\n    pub fn new_adc4(adc: Peri<'d, T>) -> Self {\n        rcc::enable_and_reset::<T>();\n        let prescaler = from_ker_ck(T::frequency());\n\n        T::regs().ccr().modify(|w| w.set_presc(prescaler));\n\n        let frequency = T::frequency() / prescaler;\n        info!(\"ADC4 frequency set to {}\", frequency);\n\n        if frequency > MAX_ADC_CLK_FREQ {\n            panic!(\n                \"Maximal allowed frequency for ADC4 is {} MHz and it varies with different packages, refer to ST docs for more information.\",\n                MAX_ADC_CLK_FREQ.0 / 1_000_000\n            );\n        }\n\n        T::regs().isr().modify(|w| {\n            w.set_ldordy(true);\n        });\n        T::regs().cr().modify(|w| {\n            w.set_advregen(true);\n        });\n        while !T::regs().isr().read().ldordy() {}\n\n        T::regs().isr().modify(|w| {\n            w.set_ldordy(true);\n        });\n\n        T::regs().cr().modify(|w| w.set_adcal(true));","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/adc/adc4.rs#L371-L407","documentation":"The ADC4 driver on STM32C0-family parts clocks the ADC from a kernel clock divided by a prescaler. If, even after applying the largest supported prescaler, the resulting ADC4 clock exceeds MAX_ADC_CLK_FREQ, the constructor panics because the ADC would run outside its datasheet limits, where conversions are inaccurate or unreliable. The limit depends on package/voltage, hence the pointer to ST docs.","triggerScenarios":"Calling `Adc4::new_adc4(...)` (or whatever constructs ADC4 in adc4.rs) while the ADC4 kernel clock frequency divided by the best achievable prescaler still exceeds MAX_ADC_CLK_FREQ — i.e., the peripheral clock source feeding ADC4 is configured too fast in RCC.","commonSituations":"Running the MCU at a high sysclk/PLL frequency and mapping ADC4's kernel clock from a fast bus clock without lowering it; forgetting to configure ADC4's clock source to a slower oscillator (e.g. HCLK vs. sync/ASYNC slow clock); copying RCC init code from a lower-frequency board.","solutions":["Lower the ADC4 kernel clock in your RCC config (choose a slower clock source, e.g. a divided HCLK or a low-speed oscillator)","Reduce overall system frequency so the derived ADC4 clock fits under MAX_ADC_CLK_FREQ","Check ST's datasheet/reference manual for the exact MHz limit for your specific package and voltage range"],"exampleFix":"// before\nlet config = Config::default(); // ADC4 clock derived from fast HCLK\n// after: select a slower ADC4 kernel clock in rcc\nconfig.rcc.adc4_clock_source = Some(Adc4ClockSource::HCLK / 4); // or a slow oscillator","handlingStrategy":"validation","validationCode":"// check before constructing ADC4\nlet adc_freq = adc4_kernel_clock_hz; // from your RCC config\nlet max_presc = 128u32; // largest supported prescaler\nassert!(adc_freq / max_presc <= MAX_ADC_CLK_FREQ_HZ, \"ADC4 clock too high: {}\", adc_freq);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute the ADC4 kernel clock from your RCC tree before writing init code","Prefer slow clock sources (LSI/HSI/divided HCLK) for ADC kernels","Check the datasheet limit for your exact package/voltage range","Add an early debug print of the ADC frequency in bring-up"],"tags":["embedded","stm32","adc","clock-config","rust"],"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"}