diff options
| author | xoviat <[email protected]> | 2023-09-05 16:50:33 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-09-05 16:50:33 -0500 |
| commit | 7e18e5e0c123027f15dd7a75706b9950da9aed0c (patch) | |
| tree | a4c42d0b7197056d9e9e1797f120784fbdf3be75 /examples | |
| parent | e2f8bf19ea55341f274c6cb9c3650a96f4a09fe4 (diff) | |
| parent | 49ba9c3da2b6929c5ec1fb17d8c43c271a70eb34 (diff) | |
Merge branch 'stm32g4_adc' of https://github.com/daehyeok/embassy into adc-g4
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32g4/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/adc.rs | 41 |
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 | |||
| 11 | embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.3.0", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.3", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } | 13 | embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } |
| 14 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | ||
| 15 | usbd-hid = "0.6.0" | ||
| 14 | 16 | ||
| 15 | defmt = "0.3" | 17 | defmt = "0.3" |
| 16 | defmt-rtt = "0.4" | 18 | defmt-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 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::adc::{Adc, SampleTime}; | ||
| 8 | use embassy_stm32::rcc::{AdcClockSource, ClockSrc, Pll, PllM, PllN, PllR, PllSrc}; | ||
| 9 | use embassy_stm32::Config; | ||
| 10 | use embassy_time::{Delay, Duration, Timer}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | #[embassy_executor::main] | ||
| 14 | async 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 | } | ||
