Skip to content

Commit 455f407

Browse files
Disasmmvertescher
authored andcommitted
Fix plln bound check, improve docs
1 parent 08678cc commit 455f407

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/rcc.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@ impl CFGR {
303303
let vco_clkin_mhz = (base_clk as f32 / pllm as f32) / 1_000_000.0;
304304
let mut sysclk_mhz: f32 = sysclk as f32 / 1_000_000.0;
305305

306-
// PLLN, main scaler, must result in >= 192MHz and <= 432MHz, min
307-
// 50, max 432, this constraint is allways respected when vco_clkin
308-
// <= 2 MHz
306+
// PLLN, main scaler, must result in VCO frequency >=100MHz and <=432MHz,
307+
// PLLN min 50, max 432, this constraint is always respected when
308+
// vco_clkin <= 2 MHz
309309
let mut plln: f32 = 100.0;
310310
let allowed_pllp: [u8; 4] = [2, 4, 6, 8];
311311
let pllp_val = *allowed_pllp
@@ -314,7 +314,12 @@ impl CFGR {
314314
plln = ((sysclk_mhz * (*pllp as f32)) / vco_clkin_mhz).floor();
315315
let error = sysclk_mhz - ((plln / (*pllp as f32)) * vco_clkin_mhz);
316316

317-
if error < 0.0 || plln * vco_clkin_mhz > 432.0 || plln > 432.0 || plln < 100.0 {
317+
if error < 0.0
318+
|| plln * vco_clkin_mhz < 100.0
319+
|| plln * vco_clkin_mhz > 432.0
320+
|| plln < 50.0
321+
|| plln > 432.0
322+
{
318323
core::u32::MAX
319324
} else {
320325
(error * 1_000.0) as u32

0 commit comments

Comments
 (0)