aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/peripheral/scb.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/peripheral/scb.rs b/src/peripheral/scb.rs
index 2ad0770..cfd5e13 100644
--- a/src/peripheral/scb.rs
+++ b/src/peripheral/scb.rs
@@ -598,3 +598,21 @@ impl SCB {
}
}
}
+
+const SCB_AIRCR_VECTKEY: u32 = 0x05FA << 16;
+const SCB_AIRCR_PRIGROUP_MASK: u32 = 0x5 << 8;
+const SCB_AIRCR_SYSRESETREQ: u32 = 1 << 2;
+
+impl SCB {
+ /// Initiate a system reset request to reset the MCU
+ pub fn system_reset(&mut self) -> ! {
+ ::asm::dsb();
+ unsafe { self.aircr.modify(|r|
+ SCB_AIRCR_VECTKEY | // otherwise the write is ignored
+ r & SCB_AIRCR_PRIGROUP_MASK | // keep priority group unchanged
+ SCB_AIRCR_SYSRESETREQ // set the bit
+ ) };
+ ::asm::dsb();
+ loop {} // wait for the reset
+ }
+}