From 4c5ac624455971549353d37597b2eaa172213995 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Sun, 16 Jul 2023 07:42:28 +0200 Subject: [PATCH 1/3] overflow value uint32_t -> uint64_t fix #2071 --- cores/arduino/HardwareTimer.h | 2 +- libraries/SrcWrapper/src/HardwareTimer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/HardwareTimer.h b/cores/arduino/HardwareTimer.h index d975ffb1b2..c019e44043 100644 --- a/cores/arduino/HardwareTimer.h +++ b/cores/arduino/HardwareTimer.h @@ -112,7 +112,7 @@ class HardwareTimer { void setPrescaleFactor(uint32_t prescaler); // set prescaler register (which is factor value - 1) uint32_t getPrescaleFactor(); - void setOverflow(uint32_t val, TimerFormat_t format = TICK_FORMAT); // set AutoReload register depending on format provided + void setOverflow(uint64_t val, TimerFormat_t format = TICK_FORMAT); // set AutoReload register depending on format provided uint32_t getOverflow(TimerFormat_t format = TICK_FORMAT); // return overflow depending on format provided void setPWM(uint32_t channel, PinName pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback = nullptr, callback_function_t CompareCallback = nullptr); // Set all in one command freq in HZ, Duty in percentage. Including both interrupt. diff --git a/libraries/SrcWrapper/src/HardwareTimer.cpp b/libraries/SrcWrapper/src/HardwareTimer.cpp index 231f53f41d..94d6ca7841 100644 --- a/libraries/SrcWrapper/src/HardwareTimer.cpp +++ b/libraries/SrcWrapper/src/HardwareTimer.cpp @@ -518,7 +518,7 @@ uint32_t HardwareTimer::getOverflow(TimerFormat_t format) * HERTZ_FORMAT: overflow is the frequency in hertz for overflow * @retval None */ -void HardwareTimer::setOverflow(uint32_t overflow, TimerFormat_t format) +void HardwareTimer::setOverflow(uint64_t overflow, TimerFormat_t format) { uint32_t ARR_RegisterValue; uint32_t PeriodTicks; From 80993280e8516a9cb28791c3c5e077d91e5e873d Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Sun, 16 Jul 2023 07:56:46 +0200 Subject: [PATCH 2/3] PeriodTicks uint32_t -> uint64_t fix #2071 --- libraries/SrcWrapper/src/HardwareTimer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/SrcWrapper/src/HardwareTimer.cpp b/libraries/SrcWrapper/src/HardwareTimer.cpp index 94d6ca7841..3b5f2e2827 100644 --- a/libraries/SrcWrapper/src/HardwareTimer.cpp +++ b/libraries/SrcWrapper/src/HardwareTimer.cpp @@ -521,7 +521,7 @@ uint32_t HardwareTimer::getOverflow(TimerFormat_t format) void HardwareTimer::setOverflow(uint64_t overflow, TimerFormat_t format) { uint32_t ARR_RegisterValue; - uint32_t PeriodTicks; + uint64_t PeriodTicks; uint32_t Prescalerfactor; uint32_t period_cyc; // Remark: Hardware register correspond to period count-1. Example ARR register value 9 means period of 10 timer cycle From be7e1271d224d2e04f18bb68355ed8771b384cf8 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Sun, 16 Jul 2023 08:16:21 +0200 Subject: [PATCH 3/3] add fix #2071 modification also to getter --- cores/arduino/HardwareTimer.h | 2 +- libraries/SrcWrapper/src/HardwareTimer.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cores/arduino/HardwareTimer.h b/cores/arduino/HardwareTimer.h index c019e44043..17fd4a14fb 100644 --- a/cores/arduino/HardwareTimer.h +++ b/cores/arduino/HardwareTimer.h @@ -113,7 +113,7 @@ class HardwareTimer { uint32_t getPrescaleFactor(); void setOverflow(uint64_t val, TimerFormat_t format = TICK_FORMAT); // set AutoReload register depending on format provided - uint32_t getOverflow(TimerFormat_t format = TICK_FORMAT); // return overflow depending on format provided + uint64_t getOverflow(TimerFormat_t format = TICK_FORMAT); // return overflow depending on format provided void setPWM(uint32_t channel, PinName pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback = nullptr, callback_function_t CompareCallback = nullptr); // Set all in one command freq in HZ, Duty in percentage. Including both interrupt. void setPWM(uint32_t channel, uint32_t pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback = nullptr, callback_function_t CompareCallback = nullptr); diff --git a/libraries/SrcWrapper/src/HardwareTimer.cpp b/libraries/SrcWrapper/src/HardwareTimer.cpp index 3b5f2e2827..69adea0de1 100644 --- a/libraries/SrcWrapper/src/HardwareTimer.cpp +++ b/libraries/SrcWrapper/src/HardwareTimer.cpp @@ -483,18 +483,18 @@ void HardwareTimer::setPrescaleFactor(uint32_t prescaler) * MICROSEC_FORMAT: return number of microsecondes for overflow * HERTZ_FORMAT: return frequency in hertz for overflow */ -uint32_t HardwareTimer::getOverflow(TimerFormat_t format) +uint64_t HardwareTimer::getOverflow(TimerFormat_t format) { // Hardware register correspond to period count-1. Example ARR register value 9 means period of 10 timer cycle uint32_t ARR_RegisterValue = LL_TIM_GetAutoReload(_timerObj.handle.Instance); uint32_t Prescalerfactor = LL_TIM_GetPrescaler(_timerObj.handle.Instance) + 1; - uint32_t return_value; + uint64_t return_value; switch (format) { case MICROSEC_FORMAT: - return_value = (uint32_t)(((ARR_RegisterValue + 1) * Prescalerfactor * 1000000.0) / getTimerClkFreq()); + return_value = (uint64_t)(((ARR_RegisterValue + 1) * Prescalerfactor * 1000000.0) / getTimerClkFreq()); break; case HERTZ_FORMAT: - return_value = (uint32_t)(getTimerClkFreq() / ((ARR_RegisterValue + 1) * Prescalerfactor)); + return_value = (uint64_t)(getTimerClkFreq() / ((ARR_RegisterValue + 1) * Prescalerfactor)); break; case TICK_FORMAT: default :