diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2025-04-07 11:55:50 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2025-04-17 12:07:44 -0400 |
commit | 7a9b06ad867259f48ec0393701b8c9963c5a6610 (patch) | |
tree | 2e9ab5999bb39b5e658fd9bcf6d164c1e96cd8db | |
parent | acd96047de62077e2ec175c2181317fca79f18ac (diff) | |
download | kutter-7a9b06ad867259f48ec0393701b8c9963c5a6610.tar.gz kutter-7a9b06ad867259f48ec0393701b8c9963c5a6610.tar.xz kutter-7a9b06ad867259f48ec0393701b8c9963c5a6610.zip |
stm32: Fix prescaler overflow check in hard_pwm.c
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | src/stm32/hard_pwm.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/stm32/hard_pwm.c b/src/stm32/hard_pwm.c index bbdd18b2..09a29ed5 100644 --- a/src/stm32/hard_pwm.c +++ b/src/stm32/hard_pwm.c @@ -291,10 +291,10 @@ gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val){ if (pclock_div > 1) pclock_div /= 2; // Timers run at twice the normal pclock frequency uint32_t prescaler = cycle_time / (pclock_div * (MAX_PWM - 1)); - if (prescaler > 0) { - prescaler -= 1; - } else if (prescaler > UINT16_MAX) { + if (prescaler > UINT16_MAX) { prescaler = UINT16_MAX; + } else if (prescaler > 0) { + prescaler -= 1; } gpio_peripheral(p->pin, p->function, 0); |