diff --git a/examples/mps3-an536/Cargo.toml b/examples/mps3-an536/Cargo.toml index 99a9d15..2f54c88 100644 --- a/examples/mps3-an536/Cargo.toml +++ b/examples/mps3-an536/Cargo.toml @@ -16,6 +16,7 @@ cortex-ar = { path = "../../cortex-ar", features = ["critical-section-single-cor cortex-r-rt = { path = "../../cortex-r-rt" } semihosting = { version = "0.1.18", features = ["stdio"] } arm-gic = { git = "https://github.com/google/arm-gic.git", rev = "46a8fc1720f5c28fccf4dfb5953b88dab7012e9c", optional = true } +critical-section = "1.2.0" [build-dependencies] arm-targets = {version = "0.1.0", path = "../../arm-targets"} diff --git a/examples/mps3-an536/src/bin/critical_section.rs b/examples/mps3-an536/src/bin/critical_section.rs new file mode 100644 index 0000000..66f4022 --- /dev/null +++ b/examples/mps3-an536/src/bin/critical_section.rs @@ -0,0 +1,38 @@ +//! critical-section example for Arm Cortex-R + +#![no_std] +#![no_main] + +use core::cell::RefCell; + +// pull in our start-up code +use mps3_an536 as _; + +use semihosting::println; + +struct Data { + value: u32 +} + +static GLOBAL_DATA: critical_section::Mutex> = critical_section::Mutex::new(RefCell::new(Data { value: 100 })); + +/// The entry-point to the Rust application. +/// +/// It is called by the start-up code in `cortex-m-rt`. +#[no_mangle] +pub extern "C" fn kmain() { + main(); +} + +/// The main function of our Rust application. +/// +/// Called by [`kmain`]. +fn main() -> ! { + let value = critical_section::with(|cs| { + let mut data = GLOBAL_DATA.borrow_ref_mut(cs); + data.value += 1; + data.value + }); + println!("Data is {}", value); + panic!("I am an example panic"); +}