Skip to content

Commit 386f72f

Browse files
committed
panic if STM32 clock prescaler value overflows
1 parent 42ebfe5 commit 386f72f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

rtic-monotonics/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
77

88
## Unreleased
99

10+
### Changed
11+
- Panic if STM32 prescaler value would overflow
12+
1013
## v2.1.0 - 2025-06-22
1114

1215
### Changed

rtic-monotonics/src/stm32.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ macro_rules! make_timer {
238238
$timer.cr1().modify(|r| r.set_cen(false));
239239

240240
assert!((tim_clock_hz % timer_hz) == 0, "Unable to find suitable timer prescaler value!");
241-
let psc = tim_clock_hz / timer_hz - 1;
242-
$timer.psc().write(|r| r.set_psc(psc as u16));
241+
let psc = u16::try_from(tim_clock_hz / timer_hz - 1).expect("Clock prescaler overflowed!");
242+
$timer.psc().write(|r| r.set_psc(psc));
243243

244244
// Enable full-period interrupt.
245245
$timer.dier().modify(|r| r.set_uie(true));

0 commit comments

Comments
 (0)