-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathdelay.rs
45 lines (33 loc) · 1.15 KB
/
delay.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
//! "Blinky" using delays instead of a timer
#![deny(unsafe_code)]
#![no_main]
#![no_std]
use panic_halt as _;
use cortex_m_rt::entry;
use stm32f1xx_hal::{pac, prelude::*};
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
let mut flash = dp.FLASH.constrain();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut gpioc = dp.GPIOC.split();
#[cfg(feature = "stm32f100")]
let mut led = gpioc.pc9.into_push_pull_output(&mut gpioc.crh);
#[cfg(feature = "stm32f101")]
let mut led = gpioc.pc9.into_push_pull_output(&mut gpioc.crh);
#[cfg(any(feature = "stm32f103", feature = "stm32f105", feature = "stm32f107"))]
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
//let mut delay = hal::timer::Timer::syst(cp.SYST, &clocks).delay();
// or
let mut delay = cp.SYST.delay(&clocks);
loop {
led.set_high();
// Use `embedded_hal_02::DelayMs` trait
delay.delay_ms(1_000_u16);
led.set_low();
// or use `fugit` duration units
delay.delay(1.secs());
}
}