Skip to content

Commit 6564a9f

Browse files
committed
Fix PllaClock configure() to set the freq. properly.
1 parent 01d53fa commit 6564a9f

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Added
66
- Added `build.rs` to check if memory.x changed
77

8+
### Fixed
9+
- PllaClock was not setting the freq. correctly.
10+
811
## [v0.4.6] 2025-03-31
912

1013
### Changed

hal/src/clocks/pllack.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ impl Token<PllaClock> {
1818
source: &impl PllaSource,
1919
PllaConfig { div, mult }: PllaConfig,
2020
) -> Result<PllaClock, ClockError> {
21-
if !(2..=63).contains(&mult) {
21+
if !(2..=62).contains(&mult) {
2222
return Err(ClockError::InvalidPllaCk);
2323
}
24+
// Datasheet error, sec 31.17 (step 6) & 31.20.10 differ.
2425
if div == 0 || div > 127 {
2526
return Err(ClockError::InvalidPllaCk);
2627
}
@@ -38,7 +39,8 @@ impl Token<PllaClock> {
3839
while self.pmc().sr().read().locka().bit_is_clear() {}
3940

4041
Ok(PllaClock {
41-
freq: (source.freq().convert() / div as u32) * mult as u32,
42+
// Per datasheet sec. 31.20.10, chip adds 1 to the multiplier.
43+
freq: (source.freq().convert() / div as u32) * (mult + 1) as u32,
4244
})
4345
}
4446
}

0 commit comments

Comments
 (0)