stm32f4disc-demo/src/main.rs

53 lines
1.4 KiB
Rust
Raw Normal View History

2019-02-28 22:52:49 +01:00
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
2019-02-28 22:52:49 +01:00
extern crate panic_semihosting;
//use cortex_m_semihosting::hprintln;
use hal::gpio::{ExtiPin, Output, PushPull};
2019-02-28 22:52:49 +01:00
use hal::prelude::*;
use rtfm::app;
type Led = hal::gpio::gpiod::PD<Output<PushPull>>;
const PERIOD: u32 = 8_000_000;
#[app(device = hal::stm32)]
const APP: () = {
static mut index: usize = ();
static mut leds: [Led; 4] = ();
#[init(spawn = [switch_leds])]
fn init() -> init::LateResources {
// Set up the LEDs and spawn the LEDs switch task.
let gpiod = device.GPIOD.split();
let leds = [
gpiod.pd12.into_push_pull_output().downgrade(),
gpiod.pd13.into_push_pull_output().downgrade(),
gpiod.pd14.into_push_pull_output().downgrade(),
gpiod.pd15.into_push_pull_output().downgrade(),
];
spawn.switch_leds().unwrap();
init::LateResources { index: 0, leds }
}
#[task(schedule = [switch_leds], resources = [index, leds])]
fn switch_leds() {
let index = *resources.index;
let num_leds = resources.leds.len();
resources.leds[index].set_high();
resources.leds[(index + 2) % num_leds].set_low();
*resources.index = (index + 1) % 4;
schedule.switch_leds(scheduled + PERIOD.cycles()).unwrap();
}
2019-02-28 22:52:49 +01:00
extern "C" {
fn UART4();
2019-02-28 22:52:49 +01:00
}
};