Skip to content

H7: keep PLL2 input within the wide VCO's 2-16 MHz range (SD card / FDCAN clock) - #12185

Open
sensei-hacker wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
sensei-hacker:fix-h7-pll2-vci-range
Open

sensei-hacker wants to merge 2 commits into
iNavFlight:maintenance-10.xfrom
sensei-hacker:fix-h7-pll2-vci-range

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Summary

PLL2 drives the kernel clocks for SDMMC (SD card blackbox) and FDCAN (DroneCAN). On 8 MHz HSE boards its input has been 1.6 MHz (M=5) since H7 support was added. KAKUTEH7WING (16 MHz HSE, M=10) uses the same input.

That input is out of spec for the configuration in use. The datasheet (DS12110, rev Y Table 50 and rev V Table 147) gives these limits:

VCO Input clock VCO output
Wide (used here) 2-16 MHz 192-836 MHz (960 rev V)
Medium 1-2 MHz 150-420 MHz

The code pairs a 1.6 MHz input with an 800 MHz VCO, which satisfies neither row. A PLL run out of spec can still lock but with excess jitter or marginal lock. That would be consistent with the unreliable SD card reports on H7. DroneCAN is new in 10.x, so it has little field time on this clock.

Change

The VCO stays at 800 MHz, so the P/Q/R outputs (400/80/200 MHz) do not change. Only the input divider and range change:

HSE Before After
8 MHz M=5, N=500, VCI 1.6 MHz, RANGE_0 M=2, N=200, VCI 4 MHz, RANGE_2
16 MHz M=10, N=500, VCI 1.6 MHz, RANGE_0 M=4, N=200, VCI 4 MHz, RANGE_2
25 MHz (see #12184) M=5, N=160, VCI 5 MHz, RANGE_2

An unsupported HSE value now gives a clear #error.

PLL1 (CPU clock) already uses a 2 MHz input and is not touched here.

This PR is stacked on #12184 (25 MHz HSE support, same lines). Its first commit is #12184's; please merge #12184 first, or review only the second commit.

Testing

  • Builds with no warnings: MATEKH743 (8 MHz, SDIO + DroneCAN), KAKUTEH7WING (16 MHz, SDIO), SYNERDUINOH7 and SYNERDUINOH7A (25 MHz).
  • Not yet tested on hardware. Needed: on an H7 board, long blackbox logging to SD card, sd_info / MSC mode, and DroneCAN node communication if available.

SYNERDUINOH7 and SYNERDUINOH7A (HSE_MHZ 25) fail to build: the PLL2
block asserts HSE_VALUE is a multiple of 1.6 MHz.

For a 25 MHz HSE, use M=10 (VCI 2.5 MHz, inside the 2-16 MHz input
range the wide VCO requires per DS12110 Table 50) and scale N so both
PLLs keep their existing VCO frequencies:
- PLL2: N=320, VCO 800 MHz, VCI range 2-4 MHz
- PLL1: N scaled by 4/5 (320/384), VCO 800/960 MHz as with 8/16 MHz HSE

Previously PLL1 used M=12 for 25 MHz, giving 417 MHz (rev Y) and an
out-of-spec 1000 MHz VCO / 500 MHz core (rev V).

Builds for 8 and 16 MHz HSE targets are unchanged.
PLL2 (SDMMC and FDCAN kernel clock) ran with a 1.6 MHz input
(8 MHz HSE / 5) on the wide VCO, which DS12110 Tables 50 and 147
specify for 2-16 MHz input only. The medium VCO accepts 1-2 MHz but
tops out at 420 MHz, so the 800 MHz VCO was out of spec either way.

Use a 4 MHz input for 8/16 MHz HSE (M=2/4, N=200) and 5 MHz for
25 MHz HSE (M=5, N=160), with VCIRANGE_2 (4-8 MHz). The VCO stays at
800 MHz, so the P/Q/R outputs (400/80/200 MHz) are unchanged.
@sensei-hacker sensei-hacker added this to the 10.0 milestone Oct 25, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Keep STM32H7 PLL2 input within the wide-VCO range

🐞 Bug fix 🕐 20-40 Minutes

Grey Divider

AI Description

• Set PLL2 input to 4–5 MHz while preserving SDMMC and FDCAN clock outputs.
• Correct PLL1 scaling for 25 MHz HSE boards without changing intended CPU frequencies.
• Reject unsupported PLL2 HSE values at build time; hardware validation remains outstanding.
Diagram

graph TD
    HSE(["HSE oscillator"]) --> PLL1["PLL1 scaling"] --> CPU["CPU clock"]
    HSE --> VCI["PLL2 input selection"] --> PLL2["800 MHz PLL2"] --> SDMMC["SDMMC clock"]
    PLL2 --> FDCAN["FDCAN clock"]
Loading
High-Level Assessment

Retaining the existing PLL output frequencies while changing only the input dividers and range directly addresses the out-of-spec condition without requiring peripheral clock changes. A generalized divider search would add complexity for the supported HSE values; hardware validation is the remaining requirement.

Files changed (1) +24 / -11

Bug fix (1) +24 / -11
system_stm32h7xx.cCorrect PLL1 and PLL2 dividers for STM32H7 HSE frequencies +24/-11

Correct PLL1 and PLL2 dividers for STM32H7 HSE frequencies

• Scales PLL1's N divider for 25 MHz HSE to retain its intended VCO and CPU frequencies. Selects a 4 MHz PLL2 input for 8/16 MHz HSE or 5 MHz for 25 MHz HSE, sets the matching VCI range, and retains the 800 MHz VCO and SDMMC/FDCAN outputs. Unsupported PLL2 HSE values now produce a build error.

src/main/target/system_stm32h7xx.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

Copy link
Copy Markdown

RAM / Flash usage vs. base commit bc76329 — commit b205294

Target Flash Δ RAM Δ
MATEKF405 ±0 B (±0.00%) CCM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
MATEKF722 ±0 B (±0.00%) ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
TCM: ±0 B (±0.00%)
MATEKF765 ±0 B (±0.00%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: ±0 B (±0.00%)
MATEKH743 ±0 B (±0.00%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)

See RAM/flash optimization guide for techniques to reduce usage.

@github-actions

Copy link
Copy Markdown

Test firmware build ready — commit b205294

Download firmware for PR #12185

251 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant