Merge pull request #1846 from diondokter/stm32-timer-prevent-hardfault

Stm32 timer prevent hardfault when frequency is 0
This commit is contained in:
Dario Nieuwenhuis 2023-08-30 17:40:06 +00:00 committed by GitHub
commit 5c936d33d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,6 +211,7 @@ macro_rules! impl_basic_16bit_timer {
use core::convert::TryInto;
let f = frequency.0;
let timer_f = Self::frequency().0;
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());
@ -255,6 +256,7 @@ macro_rules! impl_32bit_timer {
fn set_frequency(&mut self, frequency: Hertz) {
use core::convert::TryInto;
let f = frequency.0;
assert!(f > 0);
let timer_f = Self::frequency().0;
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());