From b7a8d711667a352a83dce4fd7aea99e259459633 Mon Sep 17 00:00:00 2001 From: Sadik Ozer Date: Wed, 6 Dec 2023 13:06:10 +0300 Subject: [PATCH] Fix issue: Timer PWM mode edge case issue fixed when timer period end the tmr->count is reset to 0x00000001 and the timer resumes counting. On edge case when pwm==0 flow stuck in while loop tmr->cnt newer become bigger than pwm so that +2 added Signed-off-by: Sadik Ozer --- Libraries/PeriphDrivers/Source/TMR/tmr_revb.c | 9 ++++++++- Libraries/PeriphDrivers/Source/TMR/tmr_revc.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c b/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c index ed977ad0e9d..18458da7084 100644 --- a/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c +++ b/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c @@ -269,7 +269,14 @@ int MXC_TMR_RevB_SetPWM(mxc_tmr_revb_regs_t *tmr, uint32_t pwm) return E_BAD_PARAM; } - while (tmr->cnt >= pwm) {} + /* + * when timer period end the tmr->count is reset to 0x00000001 + * and the timer resumes counting. + * On edge case when pwm==0 flow stuck in below code due to + * tmr->cnt newer become bigger than pwm. + * So that +2 added. + */ + while (tmr->cnt >= (pwm + 2)) {} tmr->pwm = pwm; while (!(tmr->intfl & MXC_F_TMR_REVB_INTFL_WRDONE_A)) {} diff --git a/Libraries/PeriphDrivers/Source/TMR/tmr_revc.c b/Libraries/PeriphDrivers/Source/TMR/tmr_revc.c index 397059d00da..b74e13aa475 100644 --- a/Libraries/PeriphDrivers/Source/TMR/tmr_revc.c +++ b/Libraries/PeriphDrivers/Source/TMR/tmr_revc.c @@ -188,7 +188,14 @@ int MXC_TMR_RevC_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm) return E_BAD_PARAM; } - while (tmr->cnt >= pwm) {} + /* + * when timer period end the tmr->count is reset to 0x00000001 + * and the timer resumes counting. + * On edge case when pwm==0 flow stuck in below code due to + * tmr->cnt newer become bigger than pwm. + * So that +2 added. + */ + while (tmr->cnt >= (pwm + 2)) {} tmr->pwm = pwm;