From e60fe3d99b545d7e42ff2f5278efa5822668a57c Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 31 Dec 2025 18:39:23 -0500 Subject: [PATCH] stm32: Fix off-by-one error in the prescaler calculation in hard_pwm.c Signed-off-by: Kevin O'Connor --- src/stm32/hard_pwm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stm32/hard_pwm.c b/src/stm32/hard_pwm.c index 0b4ea6eb3..f34e62b00 100644 --- a/src/stm32/hard_pwm.c +++ b/src/stm32/hard_pwm.c @@ -11,7 +11,7 @@ #include "internal.h" // GPIO #include "sched.h" // sched_shutdown -#define MAX_PWM (256 + 1) +#define MAX_PWM 256 DECL_CONSTANT("PWM_MAX", MAX_PWM); struct gpio_pwm_info { @@ -327,7 +327,7 @@ gpio_timer_setup(uint8_t pin, uint32_t cycle_time, uint32_t val, // In normal mode, allow the pulse frequency (cycle_time) to change // in order to maintain the requested duty ratio (val/MAX_PWM). hwpwm_ticks = MAX_PWM; - prescaler = pcycle_time / (hwpwm_ticks - 1); + prescaler = pcycle_time / MAX_PWM; if (prescaler > UINT16_MAX + 1) prescaler = UINT16_MAX + 1; else if (prescaler < 1)