aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src/bin
diff options
context:
space:
mode:
authorMatous Hybl <[email protected]>2022-03-19 11:05:00 +0100
committerMatous Hybl <[email protected]>2022-04-12 22:25:00 +0200
commit371f3ef41902bb808f9bc505c162efc55594254f (patch)
treeb72d98a8651f82758903c81c91020ea55dff9065 /examples/stm32h7/src/bin
parentac3986e40ef297b90de19812aebccfe2e7f9ceec (diff)
Add ADC support for H7
Diffstat (limited to 'examples/stm32h7/src/bin')
-rw-r--r--examples/stm32h7/src/bin/adc.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs
new file mode 100644
index 000000000..b12bca307
--- /dev/null
+++ b/examples/stm32h7/src/bin/adc.rs
@@ -0,0 +1,42 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use embassy::executor::Spawner;
6use embassy::time::{Delay, Duration, Timer};
7use embassy_stm32::adc::{Adc, SampleTime};
8use embassy_stm32::rcc::AdcClockSource;
9use embassy_stm32::time::U32Ext;
10use embassy_stm32::{Config, Peripherals};
11
12use defmt::*;
13use defmt_rtt as _; // global logger
14use panic_probe as _;
15
16pub fn config() -> Config {
17 let mut config = Config::default();
18 config.rcc.sys_ck = Some(400.mhz().into());
19 config.rcc.hclk = Some(200.mhz().into());
20 config.rcc.per_ck = Some(64.mhz().into());
21 config.rcc.adc_clock_source = AdcClockSource::PerCk;
22 config
23}
24
25#[embassy::main(config = "config()")]
26async fn main(_spawner: Spawner, mut p: Peripherals) {
27 info!("Hello World!");
28
29 let mut adc = Adc::new(p.ADC3, &mut Delay);
30
31 adc.set_sample_time(SampleTime::Cycles32_5);
32
33 let mut vref_channel = adc.enable_vref();
34
35 loop {
36 let vref = adc.read_internal(&mut vref_channel);
37 info!("vref: {}", vref);
38 let measured = adc.read(&mut p.PC0);
39 info!("measured: {}", measured);
40 Timer::after(Duration::from_millis(500)).await;
41 }
42}