@@ -18,10 +18,11 @@ use rtic_monotonic::Monotonic;
18
18
/// Note that the SysTick interrupt must not be disabled longer than half the
19
19
/// cycle counter overflow period (typically a couple seconds).
20
20
///
21
+ /// Note(Safety): Do not disable/enable or set/reset the DWT cycle counter.
22
+ ///
21
23
/// When the `extend` feature is enabled, the cycle counter width is extended to
22
24
/// `u64` by detecting and counting overflows.
23
25
pub struct DwtSystick < const TIMER_HZ : u32 > {
24
- dwt : DWT ,
25
26
systick : SYST ,
26
27
#[ cfg( feature = "extend" ) ]
27
28
last : u64 ,
@@ -34,7 +35,7 @@ impl<const TIMER_HZ: u32> DwtSystick<TIMER_HZ> {
34
35
/// so the speed calculated at runtime and the declared speed (generic parameter
35
36
/// `TIMER_HZ`) can be compared.
36
37
#[ 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 {
38
39
assert ! ( TIMER_HZ == sysclk) ;
39
40
40
41
dcb. enable_trace ( ) ;
@@ -50,7 +51,6 @@ impl<const TIMER_HZ: u32> DwtSystick<TIMER_HZ> {
50
51
// We do not start the counters here but in `reset()`.
51
52
52
53
DwtSystick {
53
- dwt,
54
54
systick,
55
55
#[ cfg( feature = "extend" ) ]
56
56
last : 0 ,
@@ -98,8 +98,8 @@ impl<const TIMER_HZ: u32> Monotonic for DwtSystick<TIMER_HZ> {
98
98
self . systick . enable_counter ( ) ;
99
99
100
100
// 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 ) ;
103
103
}
104
104
105
105
fn set_compare ( & mut self , val : Self :: Instant ) {
0 commit comments