diff options
Diffstat (limited to 'examples/stm32h7/src/bin')
| -rw-r--r-- | examples/stm32h7/src/bin/blinky.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs new file mode 100644 index 000000000..c425b7f8e --- /dev/null +++ b/examples/stm32h7/src/bin/blinky.rs | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | use embassy_stm32::gpio::{Level, Output}; | ||
| 12 | use embedded_hal::digital::v2::OutputPin; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | use cortex_m_rt::entry; | ||
| 16 | use stm32h7::stm32h743 as pac; | ||
| 17 | |||
| 18 | use stm32h7xx_hal as hal; | ||
| 19 | use hal::prelude::*; | ||
| 20 | |||
| 21 | #[entry] | ||
| 22 | fn main() -> ! { | ||
| 23 | info!("Hello World!"); | ||
| 24 | |||
| 25 | let pp = pac::Peripherals::take().unwrap(); | ||
| 26 | |||
| 27 | let pwrcfg = pp.PWR.constrain() | ||
| 28 | .freeze(); | ||
| 29 | |||
| 30 | let rcc = pp.RCC.constrain(); | ||
| 31 | |||
| 32 | let ccdr = rcc | ||
| 33 | .sys_ck(96.mhz()) | ||
| 34 | .pclk1(48.mhz()) | ||
| 35 | .pclk2(48.mhz()) | ||
| 36 | .pclk3(48.mhz()) | ||
| 37 | .pclk4(48.mhz()) | ||
| 38 | .pll1_q_ck(48.mhz()) | ||
| 39 | .freeze(pwrcfg, &pp.SYSCFG); | ||
| 40 | |||
| 41 | let pp = unsafe { pac::Peripherals::steal() }; | ||
| 42 | |||
| 43 | pp.DBGMCU.cr.modify(|_, w| { | ||
| 44 | w.dbgsleep_d1().set_bit(); | ||
| 45 | w.dbgstby_d1().set_bit(); | ||
| 46 | w.dbgstop_d1().set_bit(); | ||
| 47 | w.d1dbgcken().set_bit(); | ||
| 48 | w | ||
| 49 | }); | ||
| 50 | |||
| 51 | pp.RCC.ahb4enr.modify(|_, w| { | ||
| 52 | w.gpioaen().set_bit(); | ||
| 53 | w.gpioben().set_bit(); | ||
| 54 | w.gpiocen().set_bit(); | ||
| 55 | w.gpioden().set_bit(); | ||
| 56 | w.gpioeen().set_bit(); | ||
| 57 | w.gpiofen().set_bit(); | ||
| 58 | w | ||
| 59 | }); | ||
| 60 | |||
| 61 | let p = embassy_stm32::init(Default::default()); | ||
| 62 | |||
| 63 | let mut led = Output::new(p.PB14, Level::High); | ||
| 64 | |||
| 65 | loop { | ||
| 66 | info!("high"); | ||
| 67 | led.set_high().unwrap(); | ||
| 68 | cortex_m::asm::delay(10_000_000); | ||
| 69 | |||
| 70 | info!("low"); | ||
| 71 | led.set_low().unwrap(); | ||
| 72 | cortex_m::asm::delay(10_000_000); | ||
| 73 | } | ||
| 74 | |||
| 75 | } | ||
