mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 00:02:28 +00:00
stm32 timer: fix 32bit timer off by 1 ARR error
This commit is contained in:
parent
34074e6eb0
commit
e7bfd7bac9
@ -257,7 +257,10 @@ impl<'d, T: CoreInstance> Timer<'d, T> {
|
||||
TimerBits::Bits32 => {
|
||||
let pclk_ticks_per_timer_period = (timer_f / f) as u64;
|
||||
let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into());
|
||||
let arr: u32 = unwrap!((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into());
|
||||
let divide_by = pclk_ticks_per_timer_period / (u64::from(psc) + 1);
|
||||
|
||||
// the timer counts `0..=arr`, we want it to count `0..divide_by`
|
||||
let arr: u32 = unwrap!(u32::try_from(divide_by - 1));
|
||||
|
||||
let regs = self.regs_gp32_unchecked();
|
||||
regs.psc().write_value(psc);
|
||||
|
Loading…
Reference in New Issue
Block a user