Skip to content

Instantly share code, notes, and snippets.

@stianeklund
Created April 8, 2020 15:59
Show Gist options
  • Save stianeklund/7965a4533f99bda2a7a92ab67b0baa56 to your computer and use it in GitHub Desktop.
Save stianeklund/7965a4533f99bda2a7a92ab67b0baa56 to your computer and use it in GitHub Desktop.
Blinky
// 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 {}
}
@stianeklund
Copy link
Author

cargo.toml contents:

[package]
name = "blinky"
version = "0.1.0"
authors = ["Stian Eklund <stian.eklund@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
embedded-hal = "0.2.3"
nb = "0.1.2"
cortex-m = "0.6.2"
cortex-m-rt = "0.6.11"
# Panic behaviour, see https://crates.io/keywords/panic-impl for alternatives
panic-halt = "0.2.0"

[dependencies.stm32f4xx-hal]
version = "0.7"
features = ["rt", "stm32f429"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment