diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 5fa5b9bc..ddf06dea 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs @@ -6,6 +6,17 @@ use embedded_hal::blocking::delay::DelayUs; pub const VDDA_CALIB_MV: u32 = 3000; +/// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock +/// configuration. +unsafe fn enable() { + #[cfg(rcc_h7)] + crate::pac::RCC.apb2enr().modify(|w| w.set_adcen(true)); + #[cfg(rcc_g0)] + crate::pac::RCC.apbenr2().modify(|w| w.set_adcen(true)); + #[cfg(rcc_l4)] + crate::pac::RCC.ahb2enr().modify(|w| w.set_adcen(true)); +} + pub enum Resolution { TwelveBit, TenBit, @@ -196,6 +207,7 @@ impl<'d, T: Instance> Adc<'d, T> { pub fn new(_peri: impl Unborrow + 'd, delay: &mut impl DelayUs) -> Self { unborrow!(_peri); unsafe { + enable(); T::regs().cr().modify(|reg| { #[cfg(not(adc_g0))] reg.set_deeppwd(false);