embassy-rs/embassy · error

not implemented

Error message

not implemented

What it means

from_ker_ck computes the ADC clock prescaler from the kernel clock frequency, dividing down to reach a valid ADC clock. The final fallthrough arm uses unimplemented!(), so any frequency that does not map to prescaler Div2..Div12 (i.e. outside the handled ranges) panics with 'not implemented'.

Solutions

  1. Set the ADC kernel clock (via RCC configuration) to a frequency that maps to a supported prescaler
  2. Clamp or round the frequency before calling new_adc4 so it falls within 1..=11 of the scaling step
  3. Replace the unimplemented!() with a defensive fallback or panic message including the frequency
  4. Verify ADC clock config in RCC (adc clock source/divider) matches the datasheet range

Example fix

// before
let adc = Adc4::new(p.ADC4, Irqs, Adc4Config::default()); // with unsupported ker clock
// after
let config = Adc4Config::default().clock(/* valid frequency within prescaler table */);
let adc = Adc4::new(p.ADC4, Irqs, config);
Defensive patterns

Strategy: validation

Validate before calling

// before constructing Adc4, ensure ker_ck maps to a supported prescaler step
// step = ker_ck freq / target adc clock; must land in 1..=11
assert!((1..=11).contains(&step), "ADC4 kernel clock not prescalable: step={}", step);

Prevention

When it happens

Trigger: Creating an Adc4 via new_adc4 with a kernel clock (ker_ck) frequency whose required division does not match the ranges 1, 2..=3, 4..=5, 6..=7, 8..=9, 10..=11 after division steps.

Common situations: An unusually low or nonstandard ADC kernel clock frequency configured in RCC that falls outside the prescaler mapping table.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of embassy-rs/embassy@463a07b963 (2026-09-10). Data as JSON: /api/errors/876660ec3d1e7e1c. Report an issue: GitHub.

Appendix: source

Thrown at embassy-stm32/src/adc/adc4.rs:254

        Resolution::Bits10 => 2,
        Resolution::Bits8 => 4,
        Resolution::Bits6 => 6,
        #[allow(unreachable_patterns)]
        _ => 0,
    }
}

fn from_ker_ck(frequency: Hertz) -> Presc {
    let raw_prescaler = rcc::raw_prescaler(frequency.0, MAX_ADC_CLK_FREQ.0);
    match raw_prescaler {
        0 => Presc::Div1,
        1 => Presc::Div2,
        2..=3 => Presc::Div4,
        4..=5 => Presc::Div6,
        6..=7 => Presc::Div8,
        8..=9 => Presc::Div10,
        10..=11 => Presc::Div12,
        _ => unimplemented!(),
    }
}

impl AdcRegs for crate::pac::adc::Adc4 {
    fn data(&self) -> *mut u16 {
        crate::pac::adc::Adc4::dr(*self).as_ptr() as *mut u16
    }

    fn enable(&self) {
        if !self.cr().read().aden() || !self.isr().read().adrdy() {
            self.isr().write(|w| w.set_adrdy(true));
            self.cr().modify(|w| w.set_aden(true));
            while !self.isr().read().adrdy() {}
        }
    }

    fn start(&self) {
        // Start conversion

View on GitHub (pinned to 463a07b963)