Skip to content

Commit ced8c75

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

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Example demonstrating the skip-data-init feature
2-
//!
2+
//!
33
//! This feature is useful when using bootloaders (like RP2040's boot2) that:
44
//! 1. Copy all data from Flash to RAM
55
//! 2. Unmap the Flash from memory space
@@ -20,18 +20,26 @@
2020
#![no_main]
2121
#![no_std]
2222

23-
use panic_halt as _;
24-
2523
use cortex_m_rt::entry;
24+
use cortex_m_semihosting::hprintln;
25+
use panic_halt as _;
2626

2727
static mut COUNTER: u32 = 42;
2828

2929
#[entry]
3030
fn main() -> ! {
31-
unsafe {
31+
let (prev, new) = unsafe {
3232
COUNTER += 1;
33+
(COUNTER - 1, COUNTER)
34+
};
35+
36+
hprintln!("Previous counter value: {}", prev);
37+
hprintln!("New counter value: {}", new);
38+
39+
if prev != 42 || new != 43 {
40+
panic!("Unexpected COUNTER value! Data section may not be initialized.");
3341
}
34-
42+
3543
loop {
3644
cortex_m::asm::nop();
3745
}

0 commit comments

Comments
 (0)