diff --git a/src/lib.rs b/src/lib.rs index 970ed78..6d4b454 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,10 +22,11 @@ use rtic_monotonic::Monotonic; /// Note that the SysTick interrupt must not be disabled longer than half the /// cycle counter overflow period (typically a couple seconds). /// +/// Note(Safety): Do not disable/enable or set/reset the DWT cycle counter. +/// /// When the `extend` feature is enabled, the cycle counter width is extended to /// `u64` by detecting and counting overflows. pub struct DwtSystick { - dwt: DWT, systick: SYST, #[cfg(feature = "extend")] last: u64, @@ -38,7 +39,7 @@ impl DwtSystick { /// so the speed calculated at runtime and the declared speed (generic parameter /// `TIMER_HZ`) can be compared. #[inline(always)] - pub fn new(dcb: &mut DCB, mut dwt: DWT, mut systick: SYST, sysclk: u32) -> Self { + pub fn new(dcb: &mut DCB, dwt: &mut DWT, mut systick: SYST, sysclk: u32) -> Self { assert!(TIMER_HZ == sysclk); dcb.enable_trace(); @@ -54,7 +55,6 @@ impl DwtSystick { // We do not start the counters here but in `reset()`. DwtSystick { - dwt, systick, #[cfg(feature = "extend")] last: 0, @@ -102,8 +102,8 @@ impl Monotonic for DwtSystick { self.systick.enable_counter(); // Enable and reset the cycle counter to locate the epoch. - self.dwt.enable_cycle_counter(); - self.dwt.set_cycle_count(0); + (*DWT::PTR).ctrl.modify(|r| r | 1); + (*DWT::PTR).cyccnt.write(0); } fn set_compare(&mut self, val: Self::Instant) {