adc: enable ADC and clock selection for STM32WLx
This commit is contained in:
parent
bb2d6c8542
commit
0d3ff34d80
2 changed files with 30 additions and 1 deletions
|
@ -13,7 +13,7 @@ pub const VREF_CALIB_MV: u32 = 3000;
|
|||
/// configuration.
|
||||
fn enable() {
|
||||
critical_section::with(|_| {
|
||||
#[cfg(stm32h7)]
|
||||
#[cfg(any(stm32h7, stm32wl))]
|
||||
crate::pac::RCC.apb2enr().modify(|w| w.set_adcen(true));
|
||||
#[cfg(stm32g0)]
|
||||
crate::pac::RCC.apbenr2().modify(|w| w.set_adcen(true));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
pub use super::bus::{AHBPrescaler, APBPrescaler, VoltageScale};
|
||||
use crate::pac::rcc::vals::Adcsel;
|
||||
use crate::pac::{FLASH, PWR, RCC};
|
||||
use crate::rcc::bd::{BackupDomain, RtcClockSource};
|
||||
use crate::rcc::{set_freqs, Clocks};
|
||||
|
@ -106,6 +107,29 @@ impl Into<u8> for MSIRange {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum AdcClockSource {
|
||||
HSI16,
|
||||
PLLPCLK,
|
||||
SYSCLK,
|
||||
}
|
||||
|
||||
impl AdcClockSource {
|
||||
pub fn adcsel(&self) -> Adcsel {
|
||||
match self {
|
||||
AdcClockSource::HSI16 => Adcsel::HSI16,
|
||||
AdcClockSource::PLLPCLK => Adcsel::PLLPCLK,
|
||||
AdcClockSource::SYSCLK => Adcsel::SYSCLK,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AdcClockSource {
|
||||
fn default() -> Self {
|
||||
Self::HSI16
|
||||
}
|
||||
}
|
||||
|
||||
/// Clocks configutation
|
||||
pub struct Config {
|
||||
pub mux: ClockSrc,
|
||||
|
@ -116,6 +140,7 @@ pub struct Config {
|
|||
pub enable_lsi: bool,
|
||||
pub enable_rtc_apb: bool,
|
||||
pub rtc_mux: RtcClockSource,
|
||||
pub adc_clock_source: AdcClockSource,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -130,6 +155,7 @@ impl Default for Config {
|
|||
enable_lsi: false,
|
||||
enable_rtc_apb: false,
|
||||
rtc_mux: RtcClockSource::LSI,
|
||||
adc_clock_source: AdcClockSource::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -299,6 +325,9 @@ pub(crate) unsafe fn init(config: Config) {
|
|||
w.set_ppre2(config.apb2_pre.into());
|
||||
});
|
||||
|
||||
// ADC clock MUX
|
||||
RCC.ccipr().modify(|w| w.set_adcsel(config.adc_clock_source.adcsel()));
|
||||
|
||||
// TODO: switch voltage range
|
||||
|
||||
if config.enable_lsi {
|
||||
|
|
Loading…
Reference in a new issue