aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-09-05 16:50:33 -0500
committerxoviat <[email protected]>2023-09-05 16:50:33 -0500
commit7e18e5e0c123027f15dd7a75706b9950da9aed0c (patch)
treea4c42d0b7197056d9e9e1797f120784fbdf3be75 /examples
parente2f8bf19ea55341f274c6cb9c3650a96f4a09fe4 (diff)
parent49ba9c3da2b6929c5ec1fb17d8c43c271a70eb34 (diff)
Merge branch 'stm32g4_adc' of https://github.com/daehyeok/embassy into adc-g4
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32g4/Cargo.toml2
-rw-r--r--examples/stm32g4/src/bin/adc.rs41
2 files changed, 43 insertions, 0 deletions
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml
index 0c1cdd67c..2e81d2060 100644
--- a/examples/stm32g4/Cargo.toml
+++ b/examples/stm32g4/Cargo.toml
@@ -11,6 +11,8 @@ embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["de
11embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 13embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
14embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
15usbd-hid = "0.6.0"
14 16
15defmt = "0.3" 17defmt = "0.3"
16defmt-rtt = "0.4" 18defmt-rtt = "0.4"
diff --git a/examples/stm32g4/src/bin/adc.rs b/examples/stm32g4/src/bin/adc.rs
new file mode 100644
index 000000000..a792748bc
--- /dev/null
+++ b/examples/stm32g4/src/bin/adc.rs
@@ -0,0 +1,41 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::adc::{Adc, SampleTime};
8use embassy_stm32::rcc::{AdcClockSource, ClockSrc, Pll, PllM, PllN, PllR, PllSrc};
9use embassy_stm32::Config;
10use embassy_time::{Delay, Duration, Timer};
11use {defmt_rtt as _, panic_probe as _};
12
13#[embassy_executor::main]
14async fn main(_spawner: Spawner) {
15 let mut config = Config::default();
16
17 config.rcc.pll = Some(Pll {
18 source: PllSrc::HSI16,
19 prediv_m: PllM::Div4,
20 mul_n: PllN::Mul85,
21 div_p: None,
22 div_q: None,
23 // Main system clock at 170 MHz
24 div_r: Some(PllR::Div2),
25 });
26
27 config.rcc.adc12_clock_source = AdcClockSource::SysClk;
28 config.rcc.mux = ClockSrc::PLL;
29
30 let mut p = embassy_stm32::init(config);
31 info!("Hello World!");
32
33 let mut adc = Adc::new(p.ADC2, &mut Delay);
34 adc.set_sample_time(SampleTime::Cycles32_5);
35
36 loop {
37 let measured = adc.read(&mut p.PA7);
38 info!("measured: {}", measured);
39 Timer::after(Duration::from_millis(500)).await;
40 }
41}