Skip to content

Commit 4e1a257

Browse files
Sh3Rm4napatrushev
andauthored
Extend ticks calculation in timer start from u32 to u64 (#356)
Supersedes #343 Fixes #342 Co-authored-by: Anton Patrushev <apatrushev@gmail.com>
1 parent d7da223 commit 4e1a257

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3838
### Fixed
3939

4040
- Fix wrong timer frequency calculation and unexpected panics ([#338])
41+
- Fixed integer saturation in Timer::start, see #342 ([#356])
4142

4243
### Changed
4344

@@ -614,6 +615,7 @@ let clocks = rcc
614615
[defmt]: https://github.com/knurling-rs/defmt
615616
[filter]: https://defmt.ferrous-systems.com/filtering.html
616617

618+
[#356]: https://github.com/stm32-rs/stm32f3xx-hal/pull/356
617619
[#352]: https://github.com/stm32-rs/stm32f3xx-hal/pull/352
618620
[#351]: https://github.com/stm32-rs/stm32f3xx-hal/pull/351
619621
[#350]: https://github.com/stm32-rs/stm32f3xx-hal/pull/350

src/timer.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,10 @@ where
281281
let timeout: Self::Time = timeout.into();
282282
let clock = TIM::clock(&self.clocks);
283283

284-
let ticks = clock.integer().saturating_mul(timeout.integer()) * *timeout.scaling_factor();
284+
let ticks = u64::from(clock.integer()).saturating_mul(u64::from(timeout.integer()))
285+
* *timeout.scaling_factor();
285286

286-
let psc: u32 = (ticks.saturating_sub(1)) / (1 << 16);
287+
let psc = ticks.saturating_sub(1) / (1 << 16);
287288
self.tim.set_psc(crate::unwrap!(u16::try_from(psc).ok()));
288289

289290
let mut arr = ticks / psc.saturating_add(1);

0 commit comments

Comments
 (0)