Skip to content

Commit 0769f09

Browse files
committed
panic if STM32 clock prescaler value overflows
1 parent 42ebfe5 commit 0769f09

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

rtic-monotonics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
1313

1414
- Updated esp32c3 dependency to v0.28.0
1515
- Updated esp32c3 dependency to v0.27.0
16+
- Panic if STM32 prescaler value would overflow
1617

1718
### Added
1819

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)