File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 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
2020#![ no_main]
2121#![ no_std]
2222
23- use panic_halt as _;
24-
2523use cortex_m_rt:: entry;
24+ use cortex_m_semihosting:: hprintln;
25+ use panic_halt as _;
2626
2727static mut COUNTER : u32 = 42 ;
2828
2929#[ entry]
3030fn 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 }
You can’t perform that action at this time.
0 commit comments