Skip to content
Snippets Groups Projects
Commit 7e3b05d5 authored by Per Lindgren's avatar Per Lindgren
Browse files

blinky using systic delay

parent 0ba359bb
No related branches found
No related tags found
No related merge requests found
...@@ -8,14 +8,10 @@ extern crate cortex_m; ...@@ -8,14 +8,10 @@ extern crate cortex_m;
extern crate stm32f4x_hal as f4; extern crate stm32f4x_hal as f4;
use f4::stm32f4x; use f4::stm32f4x;
// use f3::hal::delay::Delay; use f4::delay::Delay;
use f4::prelude::*; use f4::prelude::*;
use f4::led::Led; use f4::led::Led;
fn wait(v: u32) {
for _ in 0..v {}
}
fn main() { fn main() {
let cp = cortex_m::Peripherals::take().unwrap(); let cp = cortex_m::Peripherals::take().unwrap();
let dp = stm32f4x::Peripherals::take().unwrap(); let dp = stm32f4x::Peripherals::take().unwrap();
...@@ -27,19 +23,17 @@ fn main() { ...@@ -27,19 +23,17 @@ fn main() {
// // clock configuration using the default settings (all clocks run at 8 MHz) // // 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) // // 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 let mut led: Led = gpioa
.pa5 .pa5
.into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper) .into_push_pull_output(&mut gpioa.moder, &mut gpioa.otyper)
.into(); .into();
// let mut delay = Delay::new(cp.SYST, clocks); let mut delay = Delay::new(cp.SYST, clocks);
loop { loop {
led.on(); led.on();
wait(10000); delay.delay_ms(1_000_u16);
// delay.delay_ms(1_000_u16);
led.off(); led.off();
wait(10000); delay.delay_ms(1_000_u16);
// delay.delay_ms(1_000_u16);
} }
} }
...@@ -15,6 +15,7 @@ pub struct Delay { ...@@ -15,6 +15,7 @@ pub struct Delay {
impl Delay { impl Delay {
/// Configures the system timer (SysTick) as a delay provider /// Configures the system timer (SysTick) as a delay provider
/// Uses the Core clock
pub fn new(mut syst: SYST, clocks: Clocks) -> Self { pub fn new(mut syst: SYST, clocks: Clocks) -> Self {
syst.set_clock_source(SystClkSource::Core); syst.set_clock_source(SystClkSource::Core);
......
...@@ -28,7 +28,7 @@ extern crate embedded_hal as hal; ...@@ -28,7 +28,7 @@ extern crate embedded_hal as hal;
extern crate nb; extern crate nb;
pub extern crate stm32f413 as stm32f4x; pub extern crate stm32f413 as stm32f4x;
// pub mod delay; pub mod delay;
pub mod flash; pub mod flash;
pub mod gpio; pub mod gpio;
// pub mod i2c; // pub mod i2c;
......
//! Prelude //! 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 hal::prelude::*;
pub use rcc::RccExt as _stm32f4x_hal_rcc_RccExt; pub use rcc::RccExt as _stm32f4x_hal_rcc_RccExt;
// pub use time::U32Ext as _stm32f30x_hal_time_U32Ext; pub use time::U32Ext as _stm32f4x_hal_time_U32Ext;
pub use flash::FlashExt as _stm32f30x_hal_flash_FlashExt; pub use flash::FlashExt as _stm32f4x_hal_flash_FlashExt;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment