2019-02-28 22:52:49 +01:00
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(warnings)]
|
|
|
|
#![no_main]
|
2019-03-05 15:05:45 +01:00
|
|
|
#![no_std]
|
2019-02-28 22:52:49 +01:00
|
|
|
|
|
|
|
extern crate panic_semihosting;
|
|
|
|
|
|
|
|
//use cortex_m_semihosting::hprintln;
|
2019-03-05 17:03:46 +01:00
|
|
|
use hal::gpio::{ExtiPin, Output, PushPull};
|
2019-02-28 22:52:49 +01:00
|
|
|
use hal::prelude::*;
|
2019-03-05 17:03:46 +01:00
|
|
|
use rtfm::app;
|
2019-03-05 15:05:45 +01:00
|
|
|
|
|
|
|
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] = ();
|
|
|
|
|
2019-03-05 17:03:46 +01:00
|
|
|
#[init(spawn = [switch_leds])]
|
2019-03-05 15:05:45 +01:00
|
|
|
fn init() -> init::LateResources {
|
2019-03-05 17:03:46 +01:00
|
|
|
// Set up the LEDs and spawn the LEDs switch task.
|
2019-03-05 15:05:45 +01:00
|
|
|
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(),
|
|
|
|
];
|
2019-03-05 17:03:46 +01:00
|
|
|
spawn.switch_leds().unwrap();
|
2019-03-05 15:05:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-03-05 15:05:45 +01:00
|
|
|
extern "C" {
|
|
|
|
fn UART4();
|
2019-02-28 22:52:49 +01:00
|
|
|
}
|
2019-03-05 15:05:45 +01:00
|
|
|
};
|