made adc example working with default clock configuration and switched in v1 to PCLK/2 per default

This commit is contained in:
shufps 2024-02-08 11:28:53 +01:00
parent dabe48c3bd
commit 34c71b58cf
2 changed files with 6 additions and 7 deletions

View File

@ -76,6 +76,10 @@ impl<'d, T: Instance> Adc<'d, T> {
// tstab = 14 * 1/fadc // tstab = 14 * 1/fadc
delay.delay_us(1); delay.delay_us(1);
// set default PCKL/2 on L0s because HSI is disabled in the default clock config
#[cfg(adc_l0)]
T::regs().cfgr2().modify(|reg| reg.set_ckmode(Ckmode::PCLK_DIV2));
// A.7.1 ADC calibration code example // A.7.1 ADC calibration code example
T::regs().cfgr1().modify(|reg| reg.set_dmaen(false)); T::regs().cfgr1().modify(|reg| reg.set_dmaen(false));
T::regs().cr().modify(|reg| reg.set_adcal(true)); T::regs().cr().modify(|reg| reg.set_adcal(true));

View File

@ -5,7 +5,7 @@ use defmt::*;
use embassy_executor::Spawner; use embassy_executor::Spawner;
use embassy_stm32::adc::{Adc, SampleTime}; use embassy_stm32::adc::{Adc, SampleTime};
use embassy_stm32::peripherals::ADC; use embassy_stm32::peripherals::ADC;
use embassy_stm32::{adc, bind_interrupts, Config}; use embassy_stm32::{adc, bind_interrupts};
use embassy_time::{Delay, Timer}; use embassy_time::{Delay, Timer};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
@ -15,12 +15,7 @@ bind_interrupts!(struct Irqs {
#[embassy_executor::main] #[embassy_executor::main]
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
// enable HSI because default is MSI but ADC doesn't support let p = embassy_stm32::init(Default::default());
// this as clock source on L0s and uses HSI by default
let mut config = Config::default();
config.rcc.hsi = true;
let p = embassy_stm32::init(config);
info!("Hello World!"); info!("Hello World!");
let mut adc = Adc::new(p.ADC, Irqs, &mut Delay); let mut adc = Adc::new(p.ADC, Irqs, &mut Delay);