The rtfm example becomes the new main binary
This commit is contained in:
parent
3e5088edfa
commit
66aff9a87d
|
@ -1,54 +0,0 @@
|
||||||
//! examples/rtfm.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
extern crate panic_semihosting;
|
|
||||||
|
|
||||||
//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: () = {
|
|
||||||
static mut index: usize = ();
|
|
||||||
static mut leds: [Led; 4] = ();
|
|
||||||
|
|
||||||
#[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(),
|
|
||||||
];
|
|
||||||
|
|
||||||
schedule.switch_leds(Instant::now() + PERIOD.cycles()).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();
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
fn UART4();
|
|
||||||
}
|
|
||||||
};
|
|
73
src/main.rs
73
src/main.rs
|
@ -1,47 +1,52 @@
|
||||||
#![deny(unsafe_code)]
|
#![deny(unsafe_code)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
extern crate panic_semihosting;
|
extern crate panic_semihosting;
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
|
||||||
extern crate panic_abort;
|
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
|
||||||
//use cortex_m_semihosting::hprintln;
|
//use cortex_m_semihosting::hprintln;
|
||||||
use hal::delay::Delay;
|
use hal::gpio::{Output, PushPull};
|
||||||
use hal::prelude::*;
|
use hal::prelude::*;
|
||||||
|
use rtfm::{app, Instant};
|
||||||
|
|
||||||
#[entry]
|
type Led = hal::gpio::gpiod::PD<Output<PushPull>>;
|
||||||
fn main() -> ! {
|
|
||||||
// Get handles to the hardware.
|
|
||||||
let core = cortex_m::Peripherals::take().unwrap();
|
|
||||||
let device = hal::stm32::Peripherals::take().unwrap();
|
|
||||||
|
|
||||||
// Get a clock for the delay.
|
const PERIOD: u32 = 8_000_000;
|
||||||
let rcc = device.RCC.constrain();
|
|
||||||
let clocks = rcc.cfgr.freeze();
|
|
||||||
let mut delay = Delay::new(core.SYST, clocks);
|
|
||||||
|
|
||||||
// Set up the LEDs.
|
#[app(device = hal::stm32)]
|
||||||
let gpiod = device.GPIOD.split();
|
const APP: () = {
|
||||||
let mut leds = [
|
static mut index: usize = ();
|
||||||
gpiod.pd12.into_push_pull_output().downgrade(),
|
static mut leds: [Led; 4] = ();
|
||||||
gpiod.pd13.into_push_pull_output().downgrade(),
|
|
||||||
gpiod.pd14.into_push_pull_output().downgrade(),
|
|
||||||
gpiod.pd15.into_push_pull_output().downgrade(),
|
|
||||||
];
|
|
||||||
let num_leds = leds.len();
|
|
||||||
assert_eq!(num_leds, 4);
|
|
||||||
|
|
||||||
// Blink the LED...
|
#[init(schedule = [switch_leds])]
|
||||||
loop {
|
fn init() -> init::LateResources {
|
||||||
for index in 0..num_leds {
|
// Set up the LEDs.
|
||||||
leds[index].set_high();
|
let gpiod = device.GPIOD.split();
|
||||||
leds[(index + 1) % num_leds].set_low();
|
let leds = [
|
||||||
delay.delay_ms(500u16);
|
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(),
|
||||||
|
];
|
||||||
|
|
||||||
|
schedule.switch_leds(Instant::now() + PERIOD.cycles()).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();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn UART4();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue