Skip to content

Commit a842718

Browse files
bors[bot]hdhoang
andcommitted
Merge #138
138: scb: add static version of system_reset as sys_reset r=korken89 a=hdhoang As suggested in https://github.com/ah-/anne-key/pull/94. I branched this off v0.5.8 to verify the function in that PR, and against rtfm v0.3 in hdhoang/anne-key@d6fb831 I have cloned the body of `system_reset`, do you think we should call one from the other (e.g. ignoring `self` in `system_reset`, or stealing `Peripherals` in `system_reset2`)? Co-authored-by: Hoàng Đức Hiếu <[email protected]>
2 parents c61e3af + 3605ad2 commit a842718

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
@@ -620,6 +620,7 @@ const SCB_AIRCR_SYSRESETREQ: u32 = 1 << 2;
620620

621621
impl SCB {
622622
/// Initiate a system reset request to reset the MCU
623+
#[deprecated(since = "0.6.1", note = "Use `SCB::sys_reset`")]
623624
pub fn system_reset(&mut self) -> ! {
624625
::asm::dsb();
625626
unsafe {
@@ -637,6 +638,25 @@ impl SCB {
637638
::asm::nop(); // avoid rust-lang/rust#28728
638639
}
639640
}
641+
642+
/// Initiate a system reset request to reset the MCU
643+
pub fn sys_reset() -> ! {
644+
::asm::dsb();
645+
unsafe {
646+
(*Self::ptr()).aircr.modify(
647+
|r| {
648+
SCB_AIRCR_VECTKEY | // otherwise the write is ignored
649+
r & SCB_AIRCR_PRIGROUP_MASK | // keep priority group unchanged
650+
SCB_AIRCR_SYSRESETREQ
651+
}, // set the bit
652+
)
653+
};
654+
::asm::dsb();
655+
loop {
656+
// wait for the reset
657+
::asm::nop(); // avoid rust-lang/rust#28728
658+
}
659+
}
640660
}
641661

642662
const SCB_ICSR_PENDSVSET: u32 = 1 << 28;

0 commit comments

Comments
 (0)