Skip to content

Commit 7af92c3

Browse files
Add timer example
1 parent 34ce33c commit 7af92c3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

examples/blinky_timer.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
use panic_halt;
5+
6+
use stm32f0xx_hal as hal;
7+
8+
use crate::hal::prelude::*;
9+
use crate::hal::stm32;
10+
use crate::hal::time::*;
11+
use crate::hal::timers::*;
12+
13+
use cortex_m_rt::entry;
14+
use nb::block;
15+
16+
#[entry]
17+
fn main() -> ! {
18+
if let Some(p) = stm32::Peripherals::take() {
19+
let gpioa = p.GPIOA.split();
20+
/* (Re-)configure PA1 as output */
21+
let mut led = gpioa.pa1.into_push_pull_output();
22+
23+
/* Constrain clocking registers */
24+
let rcc = p.RCC.constrain();
25+
26+
/* Configure clock to 8 MHz (i.e. the default) and freeze it */
27+
let clocks = rcc.cfgr.sysclk(8.mhz()).freeze();
28+
29+
let mut timer = Timer::tim1(p.TIM1, Hertz(1), clocks);
30+
31+
loop {
32+
led.toggle();
33+
block!(timer.wait()).ok();
34+
}
35+
}
36+
37+
loop {
38+
continue;
39+
}
40+
}

0 commit comments

Comments
 (0)