Skip to content

Commit 8816963

Browse files
authored
Merge pull request #254 from TheZoq2/fix_mono_timer
Fix mono timer
2 parents 75e1d0d + 352ad75 commit 8816963

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/time.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
//! ```
2929
3030
use core::ops;
31-
use cortex_m::peripheral::DWT;
31+
use cortex_m::peripheral::{DCB, DWT};
3232

3333
use crate::rcc::Clocks;
3434

@@ -227,14 +227,20 @@ impl_arithmetic!(MegaHertz, u32);
227227
impl_arithmetic!(Bps, u32);
228228

229229
/// A monotonic non-decreasing timer
230+
///
231+
/// This uses the timer in the debug watch trace peripheral. This means, that if the
232+
/// core is stopped, the timer does not count up. This may be relevant if you are using
233+
/// cortex_m_semihosting::hprintln for debugging in which case the timer will be stopped
234+
/// while printing
230235
#[derive(Clone, Copy)]
231236
pub struct MonoTimer {
232237
frequency: Hertz,
233238
}
234239

235240
impl MonoTimer {
236241
/// Creates a new `Monotonic` timer
237-
pub fn new(mut dwt: DWT, clocks: Clocks) -> Self {
242+
pub fn new(mut dwt: DWT, mut dcb: DCB, clocks: Clocks) -> Self {
243+
dcb.enable_trace();
238244
dwt.enable_cycle_counter();
239245

240246
// now the CYCCNT counter can't be stopped or reset

0 commit comments

Comments
 (0)