Skip to content

fix: make PLL2M dynamic to keep VCO=800MHz for any HSE frequency (closes #11594)#11603

Merged
sensei-hacker merged 14 commits into
iNavFlight:maintenance-9.xfrom
daijoubu:fix/11594-pll2-dynamic-m-divider
May 30, 2026
Merged

fix: make PLL2M dynamic to keep VCO=800MHz for any HSE frequency (closes #11594)#11603
sensei-hacker merged 14 commits into
iNavFlight:maintenance-9.xfrom
daijoubu:fix/11594-pll2-dynamic-m-divider

Conversation

@daijoubu
Copy link
Copy Markdown
Contributor

@daijoubu daijoubu commented May 30, 2026

Summary

Fixes #11594. On KAKUTEH7WING (16 MHz HSE), PLL2M was hardcoded to 5, giving VCO = 16/5 × 500 = 1600 MHz (out of spec) and SDMMC clock = 400 MHz instead of the required 200 MHz.

Fix: compute PLL2M = HSE_VALUE / 1600000, pinning VCI to exactly 1.6 MHz:

  • HSE=8 MHz → M=5, VCO=800 MHz (identical to original — no change for existing targets)
  • HSE=16 MHz → M=10, VCO=800 MHz ✓, SDMMC=200 MHz ✓

Also adds a STATIC_ASSERT to catch future targets with incompatible HSE frequencies, and checks the HAL_RCCEx_PeriphCLKConfig return value so a PLL2 lock failure halts rather than continuing silently.

Bonus fix: corrects a pre-existing PLL1 VCIRANGE mismatch (was VCIRANGE_2 / 4–8 MHz; VCI input is 2 MHz so correct range is VCIRANGE_1 / 2–4 MHz). Fixes #11602.

Changes

  • src/main/target/system_stm32h7xx.c — dynamic PLL2M, STATIC_ASSERT, Error_Handler on failure, PLL1 VCIRANGE_1
  • src/main/fc/fc_msp.c — fix sign-compare warning (unrelated build fix)

Test plan

  • Built clean for KAKUTEH7WING (H7, 16 MHz HSE) — no warnings
  • Flashed and verified board boots, CAN and SD card functional

daijoubu added 5 commits May 29, 2026 19:02
PLL2M was hardcoded to 5, which assumes HSE = 8 MHz. On KAKUTEH7WING
(HSE = 16 MHz) this gives VCO = 16/5 * 500 = 1600 MHz (out of spec)
and SDMMC clock = 400 MHz instead of the required 200 MHz.

Fix: compute PLL2M as HSE_VALUE / 1600000, pinning the VCO input to
exactly 1.6 MHz for any HSE frequency. With N=500 this gives VCO=800 MHz:

  HSE=8 MHz:  M=5,  N=500 → VCO=800 MHz (identical to original)
  HSE=16 MHz: M=10, N=500 → VCO=800 MHz (correct for KAKUTEH7WING)

PLL2R/4 = 200 MHz (SDMMC), PLL2P/2 = 400 MHz. VCIRANGE_0 (1–2 MHz)
is correct for the 1.6 MHz VCI input on all targets.

Also adds STATIC_ASSERT to catch future targets with non-multiple HSE,
and corrects the PLL2P comment (was "500Mhz", should be "400Mhz").

Fixes iNavFlight#11594
If PLL2 fails to lock at startup the SDMMC clock is dead and the SD
card will fail silently. Call Error_Handler() (infinite loop) on
failure to make the fault visible rather than continuing into
undefined behaviour.
PLL1 VCI input is HSE/M = 2 MHz on all H7 targets, which falls in the
2-4 MHz range (VCIRANGE_1). The previous VCIRANGE_2 (4-8 MHz) was
incorrect and affected PLL charge pump calibration.

Fixes iNavFlight#11602
Remove redundant prose that duplicated the assert, remove board-specific
name from shared init code, and shorten the assert slug to match
codebase conventions.
@qodo-code-review
Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@daijoubu daijoubu marked this pull request as draft May 30, 2026 03:08
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 30, 2026

Test firmware build ready — commit edb16a4

Download firmware for PR #11603

237 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

daijoubu added 8 commits May 29, 2026 20:23
PLL2M was hardcoded to 5, which assumes HSE = 8 MHz. On KAKUTEH7WING
(HSE = 16 MHz) this gives VCO = 16/5 * 500 = 1600 MHz (out of spec)
and SDMMC clock = 400 MHz instead of the required 200 MHz.

Fix: compute PLL2M as HSE_VALUE / 1600000, pinning the VCO input to
exactly 1.6 MHz for any HSE frequency. With N=500 this gives VCO=800 MHz:

  HSE=8 MHz:  M=5,  N=500 → VCO=800 MHz (identical to original)
  HSE=16 MHz: M=10, N=500 → VCO=800 MHz (correct for KAKUTEH7WING)

PLL2R/4 = 200 MHz (SDMMC), PLL2P/2 = 400 MHz. VCIRANGE_0 (1–2 MHz)
is correct for the 1.6 MHz VCI input on all targets.

Also adds STATIC_ASSERT to catch future targets with non-multiple HSE,
and corrects the PLL2P comment (was "500Mhz", should be "400Mhz").

Fixes iNavFlight#11594
If PLL2 fails to lock at startup the SDMMC clock is dead and the SD
card will fail silently. Call Error_Handler() (infinite loop) on
failure to make the fault visible rather than continuing into
undefined behaviour.
PLL1 VCI input is HSE/M = 2 MHz on all H7 targets, which falls in the
2-4 MHz range (VCIRANGE_1). The previous VCIRANGE_2 (4-8 MHz) was
incorrect and affected PLL charge pump calibration.

Fixes iNavFlight#11602
Remove redundant prose that duplicated the assert, remove board-specific
name from shared init code, and shorten the assert slug to match
codebase conventions.
@daijoubu daijoubu marked this pull request as ready for review May 30, 2026 04:05
@qodo-code-review
Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sensei-hacker sensei-hacker merged commit cf703e6 into iNavFlight:maintenance-9.x May 30, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants