We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6899a12 commit 6fc7a46Copy full SHA for 6fc7a46
cortex-m-rt/examples/skip-data-init.rs
@@ -20,16 +20,23 @@
20
#![no_main]
21
#![no_std]
22
23
-use panic_halt as _;
24
-
+use core::sync::atomic::{AtomicU32, Ordering};
25
use cortex_m_rt::entry;
+use cortex_m_semihosting::hprintln;
26
+use panic_halt as _;
27
-static mut COUNTER: u32 = 42;
28
+static COUNTER: AtomicU32 = AtomicU32::new(42);
29
30
#[entry]
31
fn main() -> ! {
- unsafe {
32
- COUNTER += 1;
+ let prev = COUNTER.fetch_add(1, Ordering::Relaxed);
33
+ let new = COUNTER.load(Ordering::Relaxed);
34
+
35
+ hprintln!("Previous counter value: {}", prev);
36
+ hprintln!("New counter value: {}", new);
37
38
+ if prev != 42 || new != 43 {
39
+ panic!("Unexpected COUNTER value! Data section may not be initialized.");
40
}
41
42
loop {
0 commit comments