Skip to content

Commit a7e62b6

Browse files
committed
add a safe method to software unlock the DWT
today the alternative is an unsafe write to the LAR register
1 parent 718cd17 commit a7e62b6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/peripheral/dwt.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,13 @@ impl DWT {
7575
// NOTE(unsafe) atomic read with no side effects
7676
unsafe { (*Self::ptr()).cyccnt.read() }
7777
}
78+
79+
/// Removes the software lock on the DWT
80+
///
81+
/// Some devices, like the STM32F7, software lock the DWT after a power cycle.
82+
#[cfg(not(armv6m))]
83+
pub fn unlock() {
84+
// NOTE(unsafe) atomic write to a stateless, write-only register
85+
unsafe { (*Self::ptr()).lar.write(0xC5ACCE55) }
86+
}
7887
}

0 commit comments

Comments
 (0)