Skip to content

Commit e5d9e75

Browse files
Stopwatch<TIM2>: Use full 32 bits when computing elapsed time
Fixes #112
1 parent fab9315 commit e5d9e75

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/timer/stopwatch.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Stopwatch<TIM> {
1212
}
1313

1414
macro_rules! stopwatches {
15-
($($TIM:ident: $tim:ident,)+) => {
15+
($($TIM:ident: $tim:ident, $depth:ident,)+) => {
1616
$(
1717
impl Stopwatch<$TIM> {
1818
pub fn $tim(tim: $TIM, rcc: &mut Rcc) -> Self {
@@ -66,7 +66,7 @@ macro_rules! stopwatches {
6666

6767
pub fn elapsed(&self, ts: Instant) -> MicroSecond {
6868
let now = self.now().ticks();
69-
let cycles = (now as u16).wrapping_sub(ts.ticks() as u16) as u32;
69+
let cycles = (now as $depth).wrapping_sub(ts.ticks() as $depth) as u32;
7070
duration(self.clk, cycles * (1 + self.tim.psc.read().bits()))
7171
}
7272

@@ -91,21 +91,21 @@ macro_rules! stopwatches {
9191
}
9292

9393
stopwatches! {
94-
TIM1: tim1,
95-
TIM3: tim3,
96-
TIM14: tim14,
97-
TIM16: tim16,
98-
TIM17: tim17,
94+
TIM1: tim1, u16,
95+
TIM3: tim3, u16,
96+
TIM14: tim14, u16,
97+
TIM16: tim16, u16,
98+
TIM17: tim17, u16,
9999
}
100100

101101
#[cfg(feature = "stm32g0x1")]
102102
stopwatches! {
103-
TIM2: tim2,
103+
TIM2: tim2, u32,
104104
}
105105

106106
#[cfg(any(feature = "stm32g070", feature = "stm32g071", feature = "stm32g081"))]
107107
stopwatches! {
108-
TIM6: tim6,
109-
TIM7: tim7,
110-
TIM15: tim15,
108+
TIM6: tim6, u16,
109+
TIM7: tim7, u16,
110+
TIM15: tim15, u16,
111111
}

0 commit comments

Comments
 (0)