Skip to content

Instantly share code, notes, and snippets.

@utzig
Created April 19, 2018 15:36
Show Gist options
  • Save utzig/59f2be8e4c94d76245f140003a24d0b2 to your computer and use it in GitHub Desktop.
Save utzig/59f2be8e4c94d76245f140003a24d0b2 to your computer and use it in GitHub Desktop.
hal_timer.c.diff
diff --git a/hw/mcu/stm/stm32_common/src/hal_timer.c b/hw/mcu/stm/stm32_common/src/hal_timer.c
index bb7fcd9e3..2b493227d 100644
--- a/hw/mcu/stm/stm32_common/src/hal_timer.c
+++ b/hw/mcu/stm/stm32_common/src/hal_timer.c
@@ -595,13 +595,14 @@ hal_timer_cnt(struct stm32_hal_tmr *tmr)
int sr;
__HAL_DISABLE_INTERRUPTS(sr);
- cnt = tmr->sht_oflow + tmr->sht_regs->CNT;
if (tmr->sht_regs->SR & TIM_SR_UIF) {
/*
* Just overflowed
*/
- cnt += STM32_OFLOW_VALUE;
+ tmr->sht_oflow += STM32_OFLOW_VALUE;
+ tmr->sht_regs->SR &= ~TIM_SR_UIF;
}
+ cnt = tmr->sht_oflow + tmr->sht_regs->CNT;
__HAL_ENABLE_INTERRUPTS(sr);
return cnt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment