mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 16:23:10 +00:00
Merge pull request #2240 from GrantM11235/fix-freq-off-by-one
stm32/timer: Fix frequency off-by-one
This commit is contained in:
commit
a31ae52d1a
@ -46,7 +46,10 @@ pub(crate) mod sealed {
|
||||
assert!(f > 0);
|
||||
let pclk_ticks_per_timer_period = timer_f / f;
|
||||
let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into());
|
||||
let arr: u16 = unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into());
|
||||
let divide_by = pclk_ticks_per_timer_period / (u32::from(psc) + 1);
|
||||
|
||||
// the timer counts `0..=arr`, we want it to count `0..divide_by`
|
||||
let arr = unwrap!(u16::try_from(divide_by - 1));
|
||||
|
||||
let regs = Self::regs();
|
||||
regs.psc().write(|r| r.set_psc(psc));
|
||||
|
Loading…
Reference in New Issue
Block a user