Skip to content

Commit 498e72a

Browse files
bors[bot]bergusjaparic
committed
Merge #94
94: Add method to trigger system reset r=japaric a=bergus Basically taken from CMSIS Co-authored-by: Bergi <[email protected]> Co-authored-by: Jorge Aparicio <[email protected]>
2 parents d663483 + 30b40eb commit 498e72a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/peripheral/scb.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,23 @@ impl SCB {
598598
}
599599
}
600600
}
601+
602+
const SCB_AIRCR_VECTKEY: u32 = 0x05FA << 16;
603+
const SCB_AIRCR_PRIGROUP_MASK: u32 = 0x5 << 8;
604+
const SCB_AIRCR_SYSRESETREQ: u32 = 1 << 2;
605+
606+
impl SCB {
607+
/// Initiate a system reset request to reset the MCU
608+
pub fn system_reset(&mut self) -> ! {
609+
::asm::dsb();
610+
unsafe { self.aircr.modify(|r|
611+
SCB_AIRCR_VECTKEY | // otherwise the write is ignored
612+
r & SCB_AIRCR_PRIGROUP_MASK | // keep priority group unchanged
613+
SCB_AIRCR_SYSRESETREQ // set the bit
614+
) };
615+
::asm::dsb();
616+
loop { // wait for the reset
617+
::asm::nop(); // avoid rust-lang/rust#28728
618+
}
619+
}
620+
}

0 commit comments

Comments
 (0)