@@ -18,10 +18,11 @@ use rtic_monotonic::Monotonic;
1818/// Note that the SysTick interrupt must not be disabled longer than half the
1919/// cycle counter overflow period (typically a couple seconds).
2020///
21+ /// Note(Safety): Do not disable/enable or set/reset the DWT cycle counter.
22+ ///
2123/// When the `extend` feature is enabled, the cycle counter width is extended to
2224/// `u64` by detecting and counting overflows.
2325pub struct DwtSystick < const TIMER_HZ : u32 > {
24- dwt : DWT ,
2526 systick : SYST ,
2627 #[ cfg( feature = "extend" ) ]
2728 last : u64 ,
@@ -34,7 +35,7 @@ impl<const TIMER_HZ: u32> DwtSystick<TIMER_HZ> {
3435 /// so the speed calculated at runtime and the declared speed (generic parameter
3536 /// `TIMER_HZ`) can be compared.
3637 #[ inline( always) ]
37- pub fn new ( dcb : & mut DCB , mut dwt : DWT , mut systick : SYST , sysclk : u32 ) -> Self {
38+ pub fn new ( dcb : & mut DCB , dwt : & mut DWT , mut systick : SYST , sysclk : u32 ) -> Self {
3839 assert ! ( TIMER_HZ == sysclk) ;
3940
4041 dcb. enable_trace ( ) ;
@@ -50,7 +51,6 @@ impl<const TIMER_HZ: u32> DwtSystick<TIMER_HZ> {
5051 // We do not start the counters here but in `reset()`.
5152
5253 DwtSystick {
53- dwt,
5454 systick,
5555 #[ cfg( feature = "extend" ) ]
5656 last : 0 ,
@@ -98,8 +98,8 @@ impl<const TIMER_HZ: u32> Monotonic for DwtSystick<TIMER_HZ> {
9898 self . systick . enable_counter ( ) ;
9999
100100 // Enable and reset the cycle counter to locate the epoch.
101- self . dwt . enable_cycle_counter ( ) ;
102- self . dwt . set_cycle_count ( 0 ) ;
101+ ( * DWT :: PTR ) . ctrl . modify ( |r| r | 1 ) ;
102+ ( * DWT :: PTR ) . cyccnt . write ( 0 ) ;
103103 }
104104
105105 fn set_compare ( & mut self , val : Self :: Instant ) {
0 commit comments