add method to trigger system reset
@@ -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
+ }
+}
