Rework the rftm example to do the same as main

This commit is contained in:
Paul van Tilburg 2019-03-05 15:05:15 +01:00
parent ff21e58323
commit 3e5088edfa
2 changed files with 40 additions and 13 deletions

View File

@ -8,12 +8,15 @@ version = "0.1.0"
[dependencies]
cortex-m = "0.5.8"
cortex-m-rt = "0.6.5"
cortex-m-rtfm = "0.4.2"
cortex-m-semihosting = "0.3.2"
panic-abort = "0.3.1"
panic-halt = "0.2.0"
panic-semihosting = "0.5.1"
[dependencies.cortex-m-rtfm]
version = "0.4.2"
features = ["timer-queue"]
[dependencies.hal]
package = "stm32f4xx-hal"
version = "0.3.0"

View File

@ -7,24 +7,48 @@
extern crate panic_semihosting;
use cortex_m_semihosting::hprintln;
use rtfm::app;
//use cortex_m_semihosting::hprintln;
use hal::gpio::{Output, PushPull};
use hal::prelude::*;
use rtfm::{app, Instant};
type Led = hal::gpio::gpiod::PD<Output<PushPull>>;
const PERIOD: u32 = 8_000_000;
#[app(device = hal::stm32)]
const APP: () = {
#[init]
fn init() {
static mut X: u32 = 0;
static mut index: usize = ();
static mut leds: [Led; 4] = ();
// Cortex-M peripherals
let _core: rtfm::Peripherals = core;
#[init(schedule = [switch_leds])]
fn init() -> init::LateResources {
// Set up the LEDs.
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(),
];
// Device specific peripherals
let _device: hal::stm32::Peripherals = device;
schedule.switch_leds(Instant::now() + PERIOD.cycles()).unwrap();
// Safe access to local `static mut` variable
let _x: &'static mut u32 = X;
init::LateResources { index: 0, leds }
}
hprintln!("init").unwrap();
#[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();
}
extern "C" {
fn UART4();
}
};