diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-11 16:20:02 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-11 16:20:02 +0000 |
| commit | 8193885cb5c1e4faa3ce884ccc6922b808208804 (patch) | |
| tree | e486d26b62dee3e969e9aa1dfe39dcf26247a9be /examples | |
| parent | 96e2f0dfc59d2e99b10cc2dd78ea0e4c16a1e15e (diff) | |
| parent | c14642cffcd7f6171ecfb107dbbd8a29ec5e2540 (diff) | |
Merge #482
482: Add MCO peripheral. r=Dirbaio a=matoushybl
This PR adds an abstraction over STM32 RCC feature called MCO (Microcontroller Clock Output). The clock output can bind to several clock sources and then can be scaled using a prescaler.
Given that from the embassy ecosystem the RCC is generaly invisible to the user, the MCO was implemented as a separate peripheral bound to the pin where the clock should appear.
Co-authored-by: Matous Hybl <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32h7/src/bin/mco.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs new file mode 100644 index 000000000..4cecd9b04 --- /dev/null +++ b/examples/stm32h7/src/bin/mco.rs | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy::time::{Duration, Timer}; | ||
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 10 | use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; | ||
| 11 | use embassy_stm32::Peripherals; | ||
| 12 | use embedded_hal::digital::v2::OutputPin; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | #[embassy::main] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | info!("Hello World!"); | ||
| 18 | |||
| 19 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); | ||
| 20 | |||
| 21 | let _mco = Mco::new(p.MCO1, p.PA8, Mco1Source::Hsi, McoClock::Divided(8)); | ||
| 22 | |||
| 23 | loop { | ||
| 24 | info!("high"); | ||
| 25 | unwrap!(led.set_high()); | ||
| 26 | Timer::after(Duration::from_millis(500)).await; | ||
| 27 | |||
| 28 | info!("low"); | ||
| 29 | unwrap!(led.set_low()); | ||
| 30 | Timer::after(Duration::from_millis(500)).await; | ||
| 31 | } | ||
| 32 | } | ||
