aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml2
-rw-r--r--ci/expected/peripherals-taken.run0
-rw-r--r--examples/peripherals-taken.rs16
-rw-r--r--macros/src/codegen/pre_init.rs7
4 files changed, 25 insertions, 0 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 54d1043e..3e5a90e5 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -174,6 +174,8 @@ jobs:
cfg
pool
ramfunc
+
+ peripherals-taken
)
for ex in ${exs[@]}; do
diff --git a/ci/expected/peripherals-taken.run b/ci/expected/peripherals-taken.run
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/ci/expected/peripherals-taken.run
diff --git a/examples/peripherals-taken.rs b/examples/peripherals-taken.rs
new file mode 100644
index 00000000..cd4ba0f0
--- /dev/null
+++ b/examples/peripherals-taken.rs
@@ -0,0 +1,16 @@
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use cortex_m_semihosting::debug;
+use panic_semihosting as _;
+
+#[rtic::app(device = lm3s6965)]
+const APP: () = {
+ #[init]
+ fn main(_: main::Context) {
+ assert!(cortex_m::Peripherals::take().is_none());
+ debug::exit(debug::EXIT_SUCCESS);
+ }
+};
diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs
index 1f1735d2..c6bd61e8 100644
--- a/macros/src/codegen/pre_init.rs
+++ b/macros/src/codegen/pre_init.rs
@@ -43,6 +43,13 @@ pub fn codegen(
let mut core: rtic::export::Peripherals = core::mem::transmute(());
));
+ if app.args.cores == 1 {
+ stmts.push(quote!(
+ // To set the variable in cortex_m so the peripherals cannot be taken multiple times
+ let _ = cortex_m::Peripherals::steal();
+ ));
+ }
+
let device = extra.device;
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);