Add ADC support for H7

This commit is contained in:
Matous Hybl
2022-03-19 11:05:00 +01:00
parent ac3986e40e
commit 371f3ef419
9 changed files with 694 additions and 13 deletions

View File

@ -8,7 +8,7 @@ resolver = "2"
[features]
[dependencies]
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime"] }
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32h743bi", "net", "time-driver-any", "exti", "unstable-pac", "unstable-traits"] }
embassy-net = { path = "../../embassy-net", default-features = false, features = ["defmt", "tcp", "medium-ethernet", "pool-16"] }

View File

@ -0,0 +1,42 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use embassy::executor::Spawner;
use embassy::time::{Delay, Duration, Timer};
use embassy_stm32::adc::{Adc, SampleTime};
use embassy_stm32::rcc::AdcClockSource;
use embassy_stm32::time::U32Ext;
use embassy_stm32::{Config, Peripherals};
use defmt::*;
use defmt_rtt as _; // global logger
use panic_probe as _;
pub fn config() -> Config {
let mut config = Config::default();
config.rcc.sys_ck = Some(400.mhz().into());
config.rcc.hclk = Some(200.mhz().into());
config.rcc.per_ck = Some(64.mhz().into());
config.rcc.adc_clock_source = AdcClockSource::PerCk;
config
}
#[embassy::main(config = "config()")]
async fn main(_spawner: Spawner, mut p: Peripherals) {
info!("Hello World!");
let mut adc = Adc::new(p.ADC3, &mut Delay);
adc.set_sample_time(SampleTime::Cycles32_5);
let mut vref_channel = adc.enable_vref();
loop {
let vref = adc.read_internal(&mut vref_channel);
info!("vref: {}", vref);
let measured = adc.read(&mut p.PC0);
info!("measured: {}", measured);
Timer::after(Duration::from_millis(500)).await;
}
}