From 0ff7023a0073873c8d6f1d77b0bbe05205da76ca Mon Sep 17 00:00:00 2001 From: Finomnis Date: Wed, 23 Oct 2024 21:08:22 +0200 Subject: [PATCH] Make initialization more deterministic --- rtic-monotonics/src/stm32.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rtic-monotonics/src/stm32.rs b/rtic-monotonics/src/stm32.rs index 156dbc25a75d..0218f1a6c61e 100644 --- a/rtic-monotonics/src/stm32.rs +++ b/rtic-monotonics/src/stm32.rs @@ -246,11 +246,16 @@ macro_rules! make_timer { // Trigger an update event to load the prescaler value to the clock. $timer.egr().write(|r| r.set_ug(true)); + // Clear timer value so it is known that we are at the first half period + $timer.cnt().write(|r| r.set_cnt(1)); + // The above line raises an update event which will indicate that the timer is already finished. // Since this is not the case, it should be cleared. $timer.sr().write(|r| { r.0 = !0; r.set_uif(false); + r.set_ccif(0, false); + r.set_ccif(1, false); }); $tq.initialize(Self {});