Skip to content

Adds an example to check critical-section works. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/mps3-an536/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
38 changes: 38 additions & 0 deletions examples/mps3-an536/src/bin/critical_section.rs
Original file line number Diff line number Diff line change
@@ -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<RefCell<Data>> = 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");
}