You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2019/09/10 02:45:00 UTC

[mynewt-core] 01/03: stm32/hal_timer: Fix prescaler handling

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit e0d6e25faba3a64b9131a20cae2e1675fa599566
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Tue Sep 3 15:27:22 2019 +0200

    stm32/hal_timer: Fix prescaler handling
    
    Code treated prescaler filed of timer peripherals PSC as it
    would be direct value while this value is 0 based when
    0 means divide by 1.
    It resulted in inaccurate time calculations.
---
 hw/mcu/stm/stm32_common/src/hal_timer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/mcu/stm/stm32_common/src/hal_timer.c b/hw/mcu/stm/stm32_common/src/hal_timer.c
index caa443b..023cf66 100644
--- a/hw/mcu/stm/stm32_common/src/hal_timer.c
+++ b/hw/mcu/stm/stm32_common/src/hal_timer.c
@@ -509,7 +509,7 @@ hal_timer_config(int num, uint32_t freq_hz)
 
     memset(&init, 0, sizeof(init));
     init.Period = 0xffff;
-    init.Prescaler = prescaler;
+    init.Prescaler = prescaler - 1;
     init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
     init.CounterMode = TIM_COUNTERMODE_UP;
 
@@ -576,7 +576,7 @@ hal_timer_get_resolution(int num)
     if (num >= STM32_HAL_TIMER_MAX || !(tmr = stm32_tmr_devs[num])) {
         return -1;
     }
-    return (STM32_NSEC_PER_SEC / (SystemCoreClock / tmr->sht_regs->PSC));
+    return (STM32_NSEC_PER_SEC / (SystemCoreClock / (1 + tmr->sht_regs->PSC)));
 }
 
 static uint32_t