Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use max frequency and round down when calculating PCLK1 #365

Merged
merged 1 commit into from
Oct 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Renamed `serial`'s `RxDma`/`TxDma`'s `split` method into `release`
- Renamed I2C's `free` method into `release`
- Enable SPI DMA in `with_tx_dma`, not in `SpiTxDma::start`
- Use maximum frequency of 36 MHz on PCLK1
- Round up when calculating the PCLK1 prescaler

## [v0.7.0]- 2020-10-17

Expand Down
20 changes: 9 additions & 11 deletions src/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,15 @@ impl CFGR {

assert!(hclk <= 72_000_000);

let ppre1_bits = self
.pclk1
.map(|pclk1| match hclk / pclk1 {
0 => unreachable!(),
1 => 0b011,
2 => 0b100,
3..=5 => 0b101,
6..=11 => 0b110,
_ => 0b111,
})
.unwrap_or(0b011);
let pclk1 = self.pclk1.unwrap_or_else(|| cmp::min(hclk, 36_000_000));
let ppre1_bits = match (hclk + pclk1 - 1) / pclk1 {
0 => unreachable!(),
1 => 0b011,
2 => 0b100,
3..=5 => 0b101,
6..=11 => 0b110,
_ => 0b111,
};

let ppre1 = 1 << (ppre1_bits - 0b011);
let pclk1 = hclk / u32(ppre1);
Expand Down