stm32-rs / stm32l0xx-hal

A hardware abstraction layer (HAL) for the STM32L0 series microcontrollers written in Rust
BSD Zero Clause License
96 stars 60 forks source link

Incorrect AHB prescaler calculation #225

Closed knoellle closed 1 year ago

knoellle commented 1 year ago

I think the AHB prescaler divisors are not correctly calculated. The enum kinds here are mapped to four bits which are then used to left-shift the divisor in here. However, there's a gap in the divisors, there is no Div32, but the bits-to-divisor calculation does not handle this gap. This means, that when a prescaler of 64 or higher is used, the reported frequency is too high by a factor of 2.

dbrgn commented 1 year ago

Without checking the datasheet: I think you're right, good catch. Would you be willing to submit a pull request with a fix?