diff --git a/.gdbinit b/.gdbinit index a5b0463..6b89d8b 100644 --- a/.gdbinit +++ b/.gdbinit @@ -4,5 +4,6 @@ monitor arm semihosting enable # monitor tpiu config internal itm.fifo uart off 8000000 # monitor itm port 0 on load -tbreak start +tbreak cortex_m_rt::reset_handler +monitor reset halt continue diff --git a/Cargo.toml b/Cargo.toml index bad8d13..d0a4b06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,9 @@ name = "cortex-m-quickstart" version = "0.0.0" [dependencies] -cortex-m = "0.2.1" +cortex-m = "0.2.2" cortex-m-rt = { git = "https://github.com/japaric/cortex-m-rt" } -cortex-m-srp = { git = "https://github.com/japaric/cortex-m-srp" } +cortex-m-srp = { git = "https://github.com/japaric/cortex-m-srp", branch = "next" } {{name}} = "*" [features] diff --git a/examples/blinky.rs b/examples/blinky.rs deleted file mode 100644 index 4259b08..0000000 --- a/examples/blinky.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! LED blinking -//! -//! This example is specific to the STM32F3DISCOVERY board - -#![feature(const_fn)] -#![no_std] - -extern crate cortex_m; -extern crate cortex_m_rt; -extern crate cortex_m_srp; -extern crate {{name}}; - -use core::cell::Cell; - -use cortex_m::ctxt::Local; -use cortex_m::exception; -use cortex_m_srp::{C0, ResourceP}; -use {{name}}::interrupt::{self, Interrupt}; - -// INITIALIZATION -fn main() { - cortex_m::interrupt::free(|cs| { - let gpioe = {{name}}::GPIOE.borrow(&cs); - let nvic = cortex_m::peripheral::NVIC.borrow(&cs); - let rcc = {{name}}::RCC.borrow(&cs); - let tim7 = {{name}}::TIM7.borrow(&cs); - - // enable peripherals - rcc.ahbenr.modify(|_, w| unsafe { w.iopeen().bits(1) }); - rcc.apb1enr.modify(|_, w| unsafe { w.tim7en().bits(1) }); - - // configure PE8 as output - gpioe.moder.modify(|_, w| unsafe { w.moder8().bits(0b01) }); - - // 1 Hz timeout - tim7.dier.modify(|_, w| unsafe { w.uie().bits(1) }); - tim7.psc.write(|w| unsafe { w.psc().bits(122) }); - tim7.arr.write(|w| unsafe { w.arr().bits(65040) }); - tim7.cr1.write(|w| unsafe { w.cen().bits(1) }); - - nvic.enable(Interrupt::Tim7); - }); -} - -// RESOURCES -static GPIOE: ResourceP<{{name}}::Gpioe, C0> = - unsafe { ResourceP::new({{name}}::GPIOE) }; - -static TIM7: ResourceP<{{name}}::Tim7, C0> = - unsafe { ResourceP::new({{name}}::TIM7) }; - -// TASKS -extern "C" fn blinky(ctxt: interrupt::Tim7) { - static STATE: Local, interrupt::Tim7> = - Local::new(Cell::new(false)); - - let gpioe = GPIOE.borrow(&ctxt); - let state = STATE.borrow(&ctxt); - let tim7 = TIM7.borrow(&ctxt); - - // Clear the update flag - tim7.sr.modify(|_, w| unsafe { w.uif().bits(0) }); - - // Toggle the state - state.set(!state.get()); - - // Blink! - if state.get() { - gpioe.bsrr.write(|w| unsafe { w.br8().bits(1) }); - } else { - gpioe.bsrr.write(|w| unsafe { w.bs8().bits(1) }); - } -} - -// GLUE -#[no_mangle] -pub static _INTERRUPTS: interrupt::Handlers = - interrupt::Handlers { tim7: blinky, ..interrupt::DEFAULT_HANDLERS }; - -#[no_mangle] -pub static _EXCEPTIONS: exception::Handlers = - exception::Handlers { ..exception::DEFAULT_HANDLERS }; diff --git a/examples/hello.rs b/examples/hello.rs index 28eceb5..ea0910f 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,5 +1,6 @@ //! Prints "Hello, world!" on the OpenOCD console using semihosting +#![feature(used)] #![no_std] #[macro_use] @@ -7,17 +8,14 @@ extern crate cortex_m; extern crate cortex_m_rt; extern crate {{name}}; -use cortex_m::exception; use {{name}}::interrupt; fn main() { hprintln!("Hello, world!"); } -#[no_mangle] -pub static _INTERRUPTS: interrupt::Handlers = +#[allow(dead_code)] +#[used] +#[link_section = ".rodata.interrupts"] +static INTERRUPTS: interrupt::Handlers = interrupt::Handlers { ..interrupt::DEFAULT_HANDLERS }; - -#[no_mangle] -pub static _EXCEPTIONS: exception::Handlers = - exception::Handlers { ..exception::DEFAULT_HANDLERS }; diff --git a/examples/itm.rs b/examples/itm.rs index 47e89de..40f66c5 100644 --- a/examples/itm.rs +++ b/examples/itm.rs @@ -5,6 +5,7 @@ //! //! [`itmdump`]: https://docs.rs/itm/0.1.1/itm/ +#![feature(used)] #![no_std] #[macro_use] @@ -12,21 +13,21 @@ extern crate cortex_m; extern crate cortex_m_rt; extern crate {{name}}; -use cortex_m::{exception, peripheral}; +use cortex_m::peripheral; use {{name}}::interrupt; fn main() { - cortex_m::interrupt::free(|cs| { - let itm = peripheral::ITM.borrow(&cs); + cortex_m::interrupt::free( + |cs| { + let itm = peripheral::ITM.borrow(&cs); - iprintln!(&itm.stim[0], "Hello, world!"); - }); + iprintln!(&itm.stim[0], "Hello, world!"); + }, + ); } -#[no_mangle] -pub static _INTERRUPTS: interrupt::Handlers = +#[allow(dead_code)] +#[used] +#[link_section = ".rodata.interrupts"] +static INTERRUPTS: interrupt::Handlers = interrupt::Handlers { ..interrupt::DEFAULT_HANDLERS }; - -#[no_mangle] -pub static _EXCEPTIONS: exception::Handlers = - exception::Handlers { ..exception::DEFAULT_HANDLERS }; diff --git a/examples/minimal.rs b/examples/minimal.rs index 64a1dc0..39ef216 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -1,20 +1,17 @@ //! Minimal application +#![feature(used)] #![no_std] -extern crate cortex_m; extern crate cortex_m_rt; extern crate {{name}}; -use cortex_m::exception; use {{name}}::interrupt; fn main() {} -#[no_mangle] -pub static _INTERRUPTS: interrupt::Handlers = +#[allow(dead_code)] +#[used] +#[link_section = ".rodata.interrupts"] +static INTERRUPTS: interrupt::Handlers = interrupt::Handlers { ..interrupt::DEFAULT_HANDLERS }; - -#[no_mangle] -pub static _EXCEPTIONS: exception::Handlers = - exception::Handlers { ..exception::DEFAULT_HANDLERS }; diff --git a/examples/srp.rs b/examples/srp.rs new file mode 100644 index 0000000..c39f1cc --- /dev/null +++ b/examples/srp.rs @@ -0,0 +1,57 @@ +#![feature(const_fn)] +#![feature(used)] +#![no_std] + +#[macro_use] +extern crate cortex_m; +extern crate cortex_m_rt; +#[macro_use] +extern crate cortex_m_srp as rtfm; +extern crate {{name}}; + +use rtfm::{C2, C4, C16, P0, P1, P3, Resource}; +use {{name}}::interrupt::{Exti0Irq, Exti1Irq}; + +static R1: Resource<(), C4> = Resource::new(()); +static R2: Resource<(), C2> = Resource::new(()); + +fn init(_ceil: C16) {} + +fn idle(_prio: P0) { + hprintln!("IDLE"); + + rtfm::request(j1); +} + +tasks!({{name}}, { + j1: (Exti0Irq, P1), + j2: (Exti1Irq, P3), +}); + +fn j1(_task: Exti0Irq, prio: P1) { + hprintln!("J1: enter"); + R2.lock( + &prio, |_, _| { + rtfm::request(j2); + hprintln!("J1: after requesting J2"); + R1.lock( + &prio, |_, _| { + hprintln!("J1(R1): before requesting J2"); + rtfm::request(j2); + hprintln!("J1(R1): after requesting J2"); + } + ); + } + ); + hprintln!("J1: exit"); +} + +fn j2(_task: Exti1Irq, prio: P3) { + hprintln!("J2: enter"); + R1.lock( + &prio, |_, _| { + hprintln!("J2(R1)"); + } + ); + hprintln!("J2: exit"); +}