diff --git a/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c b/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c index ed977ad0e9d..4f1a404103a 100644 --- a/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c +++ b/Libraries/PeriphDrivers/Source/TMR/tmr_revb.c @@ -269,7 +269,16 @@ 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 at least +2 shall be added. + * But there should be a tolerance too, to it be catched + * So that +8 added as toleransa value. + */ + while (tmr->cnt >= (pwm + 8)) {} 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..5caa0243c32 100644 --- a/Libraries/PeriphDrivers/Source/TMR/tmr_revc.c +++ b/Libraries/PeriphDrivers/Source/TMR/tmr_revc.c @@ -188,7 +188,16 @@ 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 at least +2 shall be added. + * But there should be a tolerance too, to it be catched + * So that +8 added as toleransa value. + */ + while (tmr->cnt >= (pwm + 8)) {} tmr->pwm = pwm;