stm32-rs / stm32f1xx-hal

A Rust embedded-hal HAL impl for the STM32F1 family based on japarics stm32f103xx-hal
Apache License 2.0
550 stars 173 forks source link

Fix computation of timer frequency #434

Closed SnVIZQ closed 1 year ago

SnVIZQ commented 1 year ago

Retrieving timer frequency using PwmHz::get_period() function can cause division by zero exception for certain types of frequencies which are configured by having zero in any of the PSC or ARR register - current implementation uses "clk / (psc * arr)" expression to compute the frequency.

Implementation of compute_arr_presc() sets PSC and ARR registers correctly. Performing inverse computation leads to different expression: "clk / ((psc + 1) * (arr + 1))" which properly computes timer frequency from PSC and ARR registers. This patch uses new/fixed expression for computing timer frequency.

Change log was modified.

burrbull commented 1 year ago

bors r+

bors[bot] commented 1 year ago

Build succeeded: