Created
April 8, 2020 15:59
-
-
Save stianeklund/7965a4533f99bda2a7a92ab67b0baa56 to your computer and use it in GitHub Desktop.
Blinky
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Halt on panic | |
#[allow(unused_extern_crates)] // NOTE(allow) bug rust-lang/rust#53964 | |
extern crate panic_halt; // panic handler | |
use cortex_m; | |
use cortex_m_rt::entry; | |
use stm32f4xx_hal as hal; | |
use crate::hal::{prelude::*, stm32}; | |
#[entry] | |
fn main() -> ! { | |
if let (Some(dp), Some(cp)) = ( | |
stm32::Peripherals::take(), | |
cortex_m::peripheral::Peripherals::take(), | |
) { | |
// Set up the LED. On the Nucleo-446RE it's connected to pin PA5. | |
let gpioa = dp.GPIOA.split(); | |
let mut led = gpioa.pa5.into_push_pull_output(); | |
// Set up the system clock. We want to run at 48MHz for this one. | |
let rcc = dp.RCC.constrain(); | |
let clocks = rcc.cfgr.sysclk(48.mhz()).freeze(); | |
// Create a delay abstraction based on SysTick | |
let mut delay = hal::delay::Delay::new(cp.SYST, clocks); | |
loop { | |
// On for 1s, off for 1s. | |
led.set_high().unwrap(); | |
delay.delay_ms(1000_u32); | |
led.set_low().unwrap(); | |
delay.delay_ms(1000_u32); | |
} | |
} | |
loop {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cargo.toml contents: