From ce9393dd702ef4ebc1b9486cdcb92746fc1adbb9 Mon Sep 17 00:00:00 2001 From: Michael Perkins Date: Sat, 21 Sep 2024 09:36:32 +0100 Subject: [PATCH] Don't cache TMR clock frequency if locked We have a locking mechanism so that if we've locked the TMR clock, then calling MXC_TMR_Init() function doesn't reset them. However, the lock check is implemented in MXC_TMR_RevB_SetClockSource, which is called by MXC_TMR_SetClockSource. However, MXC_TMR_SetClockSource also calls MXC_TMR_RevB_SetClockSourceFreq, which has no lock check. The result is that if MXC_TMR_Init is called with a clock source of, say, ERFO, then we cache the new frequency, 32MHz, but then don't reconfigure the MMRs to actually run using ERFO. So the TMR driver operates believing it is running at 32MHz, but actually running at something else. This means that things like the Stop Watch timer report the wrong wall time. Signed-off-by: Michael Perkins --- Libraries/PeriphDrivers/Source/TMR/tmr_revb.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c b/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c index 8b495388ee..3306d2b05f 100644 --- a/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c +++ b/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c @@ -182,6 +182,11 @@ void MXC_TMR_RevB_SetClockSourceFreq(mxc_tmr_revb_regs_t *tmr, int clksrc_freq) (void)tmr_id; MXC_ASSERT(tmr_id >= 0); + // If the clock source is locked, don't update the frequency either, as we will + // have rejected the configuration update too in MXC_TMR_RevB_SetClockSource. + if (g_is_clock_locked[tmr_id]) + return; + tmr_clksrc[tmr_id].configured = true; tmr_clksrc[tmr_id].freq = clksrc_freq; }