aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <[email protected]>2021-09-28 20:29:46 -0400
committerBen Gamari <[email protected]>2021-09-29 00:32:40 -0400
commit0b9961584b366e6d3cc83a218c8150800793cb1d (patch)
tree09d36906442e987746241dd750e936785538045b
parent573e6ec373c92e1c85f9d84b3b68f36f1e4d0dc9 (diff)
stm32/adc: Ensure that clock is enabled
Sadly due to the inconsistency in clocking configuration across devices we cannot use RccPeripheral.
-rw-r--r--embassy-stm32/src/adc/v3.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs
index 5fa5b9bc1..ddf06deae 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;
6 6
7pub const VDDA_CALIB_MV: u32 = 3000; 7pub const VDDA_CALIB_MV: u32 = 3000;
8 8
9/// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock
10/// configuration.
11unsafe fn enable() {
12 #[cfg(rcc_h7)]
13 crate::pac::RCC.apb2enr().modify(|w| w.set_adcen(true));
14 #[cfg(rcc_g0)]
15 crate::pac::RCC.apbenr2().modify(|w| w.set_adcen(true));
16 #[cfg(rcc_l4)]
17 crate::pac::RCC.ahb2enr().modify(|w| w.set_adcen(true));
18}
19
9pub enum Resolution { 20pub enum Resolution {
10 TwelveBit, 21 TwelveBit,
11 TenBit, 22 TenBit,
@@ -196,6 +207,7 @@ impl<'d, T: Instance> Adc<'d, T> {
196 pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self { 207 pub fn new(_peri: impl Unborrow<Target = T> + 'd, delay: &mut impl DelayUs<u32>) -> Self {
197 unborrow!(_peri); 208 unborrow!(_peri);
198 unsafe { 209 unsafe {
210 enable();
199 T::regs().cr().modify(|reg| { 211 T::regs().cr().modify(|reg| {
200 #[cfg(not(adc_g0))] 212 #[cfg(not(adc_g0))]
201 reg.set_deeppwd(false); 213 reg.set_deeppwd(false);