Skip to content

Commit b4a0c90

Browse files
antonok-edmAfoHT
authored andcommitted
panic if STM32 clock prescaler value overflows
1 parent 1104a12 commit b4a0c90

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,10 @@ 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 Ok(psc) = u16::try_from(tim_clock_hz / timer_hz - 1) else {
242+
panic!("Clock prescaler overflowed!");
243+
};
244+
$timer.psc().write(|r| r.set_psc(psc));
243245

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

0 commit comments

Comments
 (0)