From 7e3b05d5dc2566f7ef0fcbe56e376595e40b5b31 Mon Sep 17 00:00:00 2001
From: Per Lindgren <per.lindgren@ltu.se>
Date: Sun, 4 Feb 2018 10:42:41 +0100
Subject: [PATCH] blinky using systic delay

---
 examples/blinky.rs | 18 ++++++------------
 src/delay.rs       |  1 +
 src/lib.rs         |  2 +-
 src/prelude.rs     |  6 +++---
 4 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/examples/blinky.rs b/examples/blinky.rs
index 2570a9e..ecd1ba7 100644
--- a/examples/blinky.rs
+++ b/examples/blinky.rs
@@ -8,14 +8,10 @@ extern crate cortex_m;
 extern crate stm32f4x_hal as f4;
 
 use f4::stm32f4x;
-// use f3::hal::delay::Delay;
+use f4::delay::Delay;
 use f4::prelude::*;
 use f4::led::Led;
 
-fn wait(v: u32) {
-    for _ in 0..v {}
-}
-
 fn main() {
     let cp = cortex_m::Peripherals::take().unwrap();
     let dp = stm32f4x::Peripherals::take().unwrap();
@@ -25,21 +21,19 @@ fn main() {
     let mut gpioa = dp.GPIOA.split(&mut rcc.ahb1);
 
     // // clock configuration using the default settings (all clocks run at 8 MHz)
-    // let clocks = rcc.cfgr.freeze(&mut flash.acr);
+    //let clocks = rcc.cfgr.freeze(&mut flash.acr);
     // // TRY this alternate clock configuration (all clocks run at 16 MHz)
-    // // let clocks = rcc.cfgr.sysclk(16.mhz()).freeze(&mut flash.acr);
+    let clocks = rcc.cfgr.sysclk(16.mhz()).freeze(&mut flash.acr);
     let mut led: Led = gpioa
         .pa5
         .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper)
         .into();
-    // let mut delay = Delay::new(cp.SYST, clocks);
+    let mut delay = Delay::new(cp.SYST, clocks);
 
     loop {
         led.on();
-        wait(10000);
-        //     delay.delay_ms(1_000_u16);
+        delay.delay_ms(1_000_u16);
         led.off();
-        wait(10000);
-        //     delay.delay_ms(1_000_u16);
+        delay.delay_ms(1_000_u16);
     }
 }
diff --git a/src/delay.rs b/src/delay.rs
index dd58172..0b27293 100644
--- a/src/delay.rs
+++ b/src/delay.rs
@@ -15,6 +15,7 @@ pub struct Delay {
 
 impl Delay {
     /// Configures the system timer (SysTick) as a delay provider
+    /// Uses the Core clock
     pub fn new(mut syst: SYST, clocks: Clocks) -> Self {
         syst.set_clock_source(SystClkSource::Core);
 
diff --git a/src/lib.rs b/src/lib.rs
index 0935157..b172394 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -28,7 +28,7 @@ extern crate embedded_hal as hal;
 extern crate nb;
 pub extern crate stm32f413 as stm32f4x;
 
-// pub mod delay;
+pub mod delay;
 pub mod flash;
 pub mod gpio;
 // pub mod i2c;
diff --git a/src/prelude.rs b/src/prelude.rs
index 48bc536..4f1fe7a 100644
--- a/src/prelude.rs
+++ b/src/prelude.rs
@@ -1,7 +1,7 @@
 //! Prelude
 
-pub use gpio::GpioExt as _stm32f30x_hal_gpio_GpioExt;
+pub use gpio::GpioExt as _stm32f4x_hal_gpio_GpioExt;
 pub use hal::prelude::*;
 pub use rcc::RccExt as _stm32f4x_hal_rcc_RccExt;
-// pub use time::U32Ext as _stm32f30x_hal_time_U32Ext;
-pub use flash::FlashExt as _stm32f30x_hal_flash_FlashExt;
+pub use time::U32Ext as _stm32f4x_hal_time_U32Ext;
+pub use flash::FlashExt as _stm32f4x_hal_flash_FlashExt;
-- 
GitLab