I'm worried about the stm32_tim_getcounter funtion. It returns always 32 bits. But major stm32 timers have 16 bits counters. I think, it's not a good idea to return the memory behind the TIMx_CNT register. This changes adds the register size checking.

This commit is contained in:
Sergei Ustinov
2017-08-31 11:45:28 -06:00
committed by Gregory Nutt
parent a7fd8eb203
commit 795650a2fb
+3 -1
View File
@@ -903,7 +903,9 @@ static void stm32_tim_setperiod(FAR struct stm32_tim_dev_s *dev,
static uint32_t stm32_tim_getcounter(FAR struct stm32_tim_dev_s *dev)
{
DEBUGASSERT(dev != NULL);
return stm32_getreg32(dev, STM32_BTIM_CNT_OFFSET);
return stm32_tim_getwidth(dev) > 16 ?
stm32_getreg32(dev, STM32_BTIM_CNT_OFFSET) :
(uint32_t)stm32_getreg16(dev, STM32_BTIM_CNT_OFFSET);
}
/************************************************************************************