forked from stm32-rs/stm32h7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
blinky_timer.rs
61 lines (48 loc) · 1.5 KB
/
blinky_timer.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#![deny(warnings)]
#![no_main]
#![no_std]
#[macro_use]
mod utilities;
#[macro_use(block)]
extern crate nb;
use cortex_m_rt::entry;
use stm32h7xx_hal::hal::digital::v2::{OutputPin, ToggleableOutputPin};
use stm32h7xx_hal::{pac, prelude::*};
use log::info;
#[entry]
fn main() -> ! {
utilities::logger::init();
let cp = cortex_m::Peripherals::take().unwrap();
let dp = pac::Peripherals::take().unwrap();
// Constrain and Freeze power
info!("Setup PWR... ");
let pwr = dp.PWR.constrain();
let pwrcfg = example_power!(pwr).freeze();
// Constrain and Freeze clock
info!("Setup RCC... ");
let rcc = dp.RCC.constrain();
let ccdr = rcc.freeze(pwrcfg, &dp.SYSCFG);
info!("");
info!("stm32h7xx-hal example - Blinky timer");
info!("");
let gpioe = dp.GPIOE.split(ccdr.peripheral.GPIOE);
// Configure PE1 as output.
let mut led = gpioe.pe1.into_push_pull_output();
led.set_low().unwrap();
// Get the delay provider.
let mut delay = cp.SYST.delay(ccdr.clocks);
// Configure the timer.
let mut timer = dp.TIM2.timer(1.hz(), ccdr.peripheral.TIM2, &ccdr.clocks);
loop {
for _ in 0..5 {
// 20ms wait with timer
led.toggle().unwrap();
timer.start(20.ms());
block!(timer.wait()).ok();
// Delay for 500ms. Timer must operate correctly on next
// use.
led.toggle().unwrap();
delay.delay_ms(500_u16);
}
}
}