Skip to content

Commit e88687a

Browse files
Update skip-data-init example
1 parent ced8c75 commit e88687a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

cortex-m-rt/examples/skip-data-init.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ use cortex_m_rt::entry;
2424
use cortex_m_semihosting::hprintln;
2525
use panic_halt as _;
2626

27+
// Minimal dummy critical-section implementation for single-core boards
28+
#[no_mangle]
29+
extern "C" fn _critical_section_1_0_acquire() -> u8 {
30+
0
31+
}
32+
#[no_mangle]
33+
extern "C" fn _critical_section_1_0_release(_token: u8) {}
34+
2735
static mut COUNTER: u32 = 42;
2836

2937
#[entry]
@@ -33,9 +41,11 @@ fn main() -> ! {
3341
(COUNTER - 1, COUNTER)
3442
};
3543

44+
// Print via semihosting; ignore errors
3645
hprintln!("Previous counter value: {}", prev);
3746
hprintln!("New counter value: {}", new);
3847

48+
// Panic if data section not initialized properly
3949
if prev != 42 || new != 43 {
4050
panic!("Unexpected COUNTER value! Data section may not be initialized.");
4151
}

0 commit comments

Comments
 (0)