stm32-rs / stm32h7xx-hal

Peripheral access API for STM32H7 series microcontrollers
BSD Zero Clause License
215 stars 101 forks source link

Fix off-by-one-tick in timer period calculation #491

Closed dne closed 5 months ago

dne commented 5 months ago

STM32 timers, in upcounting mode, count from 0 to ARR (inclusive) before restarting at 0/generating an overflow event, so we need to subtract 1 from the number of desired ticks to get the correct period.

richardeoin commented 5 months ago

Thanks for the PR and catching this off-by-one error! This change invalidates a doc comment on timer.rs:427, with this change the comment needs to state that the counter reaches the ARR after N-1 ticks and restarts at zero after N ticks. Could you update it? This change will be marked Breaking in the CHANGELOG, feel free to do this now or I can add it later.

dne commented 5 months ago

This change invalidates a doc comment on timer.rs:427, with this change the comment needs to state that the counter reaches the ARR after N-1 ticks and restarts at zero after N ticks. Could you update it?

Thanks for the review. I've updated the doc comment I had missed.