From 7af92c3294d78b60c177b38fc89b99dd8617af20 Mon Sep 17 00:00:00 2001 From: David Sawatzke Date: Tue, 18 Dec 2018 12:20:14 +0100 Subject: [PATCH] Add timer example --- examples/blinky_timer.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/blinky_timer.rs diff --git a/examples/blinky_timer.rs b/examples/blinky_timer.rs new file mode 100644 index 0000000..6cf7655 --- /dev/null +++ b/examples/blinky_timer.rs @@ -0,0 +1,40 @@ +#![no_main] +#![no_std] + +use panic_halt; + +use stm32f0xx_hal as hal; + +use crate::hal::prelude::*; +use crate::hal::stm32; +use crate::hal::time::*; +use crate::hal::timers::*; + +use cortex_m_rt::entry; +use nb::block; + +#[entry] +fn main() -> ! { + if let Some(p) = stm32::Peripherals::take() { + let gpioa = p.GPIOA.split(); + /* (Re-)configure PA1 as output */ + let mut led = gpioa.pa1.into_push_pull_output(); + + /* Constrain clocking registers */ + let rcc = p.RCC.constrain(); + + /* Configure clock to 8 MHz (i.e. the default) and freeze it */ + let clocks = rcc.cfgr.sysclk(8.mhz()).freeze(); + + let mut timer = Timer::tim1(p.TIM1, Hertz(1), clocks); + + loop { + led.toggle(); + block!(timer.wait()).ok(); + } + } + + loop { + continue; + } +}