PLL2 and PLL3 phase-fractional dividers
Understand how an 18-phase VCO ring synthesizes fractional peripheral clocks without extra analog PLLs, isolate single byte lanes with hardware SET/CLR aliases, and eliminate silent 32-bit multiplication wrap.
What you'll learn
- Solve PLL2 and PLL3 PFD rates without intermediate overflow.
- Apply one six-bit FRAC lane while preserving its neighbors.
- Diagnose a valid divider setting supplied by an unsafe parent.
Why Integer Dividers Cannot Feed Modern SoC Peripherals
Suppose your i.MX6ULL system needs 396 MHz for the MMDC DDR3 memory controller, 352 MHz for high-speed bus logic, 432 MHz for QSPI flash, and 508.2 MHz for USDHC SD-card tuning—all simultaneously. If silicon designers used only ordinary integer dividers (÷1, ÷2, ÷3, ÷4) downstream of PLL2 (528 MHz), the only available frequencies would be 528 MHz, 264 MHz, 176 MHz, and 132 MHz! Building eight separate analog PLLs on silicon would waste die area and milliwatts of continuous analog loop power. How can one fixed PLL synthesize four independent, finely spaced multi-hundred-megahertz clocks at once?
The hardware solution is the Phase-Fractional Divider (PFD), depicted in Figure 1.2a. Inside PLL2 (fixed at 528 MHz) and PLL3 (USB1, fixed at 480 MHz), a 9-stage differential ring oscillator naturally exposes 18 equally spaced phase taps (p0..p17), separated by 1/18 of a parent clock period (dt = T_pll / 18). Instead of counting whole parent cycles, each PFD slice uses a digital phase accumulator that advances by PFD_FRAC phase taps (FRAC in [12, 35]) per output cycle. Because each output period spans FRAC * (T_pll / 18), output frequency follows the exact rational transfer function F_pfd = F_parent * 18 / PFD_FRAC—producing fractional step-down when FRAC > 18 (528 MHz * 18 / 24 = 396 MHz), unity pass-through at FRAC == 18, and fractional step-up faster than the parent PLL when 12 <= FRAC < 18 (480 MHz * 18 / 12 = 720 MHz)!
Figure 1.2a. Inside an 18-phase circuit (left) and the eight PFD branches on PLL2 (528 MHz) and PLL3 (480 MHz) (right) — note PFD2_528 clocking live DDR3.
mental model: A four-port laboratory manifold feeds four independent instruments from one pressurized header; shutting the valve on Port 2 to swap its nozzle must never drop pressure on Ports 0, 1, or 3.
Where it stops working: Unlike a passive fluid valve, a Phase-Fractional Divider actively steps across 18 high-frequency VCO phases; gating a live DDR3 memory clock freezes CPU instruction fetch immediately.
definition (Phase-Fractional Divider (PFD) & Packed Byte Lanes): PLL2 (528 MHz System PLL, CCM_ANALOG_PFD_528 at 0x020C8100) and PLL3 (480 MHz USB1 PLL, CCM_ANALOG_PFD_480 at 0x020C80F0) each provide four independent Phase-Fractional Divider (PFD0..PFD3) outputs governed by F_pfd = parent * 18 / FRAC for FRAC in [12, 35]. All four branches pack into a single 32-bit register as four 8-bit byte lanes (shift = 8 * lane): bits [5:0] hold writable FRAC, bit 6 (STABLE) is read-only phase status, and bit 7 (CLKGATE) gates only that lane.
Step through the lane-isolated reconfiguration sequence before inspecting the SET/CLR silicon registers:
- Step 1. Step 1: Confirm the 528 MHz or 480 MHz parent is locked and no live consumer (such as DDR3) depends on the target lane.
- Step 2. Step 2: Widen parent to uint64_t before multiplying by 18 so 9.504 GHz numerators never wrap 32-bit integers.
- Step 3. Step 3: Gate only the selected byte lane via +0x04 SET, clear 0x3F via +0x08 CLR, and insert the new 6-bit FRAC.
- Step 4. Step 4: Ungate the lane via +0x08 CLR, poll bit 6 (STABLE) with a timeout, and confirm sibling bytes stayed untouched.
Figure 1.2b. PFD updates require both 64-bit parent * 18 / FRAC arithmetic and strict single-byte lane isolation.
Packed 32-Bit Byte Lanes, Hardware SET/CLR Aliases & 64-Bit Numerators
Packing four independent peripheral clocks into one 32-bit MMIO word creates an immediate systems hazard, shown in Figure 1.2b. If a driver writes a whole-word constant to CCM_ANALOG_PFD_528 (0x020C8100) to tune PFD0 for a display test, it simultaneously overwrites PFD2 ([23:16]), which clocks the MMDC DDR3 controller! Worse, even a software read-modify-write (*pfd = (*pfd & ~mask) | val) opens a multi-instruction race window if two drivers touch adjacent lanes. To eliminate software RMW races in hardware, CCM_ANALOG provides write-one command aliases at +0x04 (SET) and +0x08 (CLR): writing 1 bits to SET sets only those flip-flops, writing 1 bits to CLR clears only those flip-flops, and 0 bits are pure silicon no-ops!
Figure 1.2b. Packed 4-byte layout of CCM_ANALOG_PFD_528 (top), atomic SET/CLR register sequence (bottom left), and why 32-bit parent * 18 wraps modulo 2^32 (bottom right).
| PFD Update Idiom | Bus Operations | Sibling Lane Safety (PFD0,1,3) | Failure Boundary & Engineering Verdict |
|---|---|---|---|
Whole-word write PFD_528 = 0x... | 1 store to 0x020C8100 | Overwrites all 4 lanes at once | Fatal in DDR: glitches PLL2_PFD2 (MMDC DDR3 clock) while tuning a sibling |
+0x04 SET / +0x08 CLR lane sequence | Gate SET, 0x3F CLR, frac SET, Gate CLR | Touchless on other 24 bits | Hardware gold standard: zero RMW race across STABLE or sibling lanes |
Masked 32-bit RMW (reg & ~(0x3FU << s)) | 1 load + 1 store | Preserves ~mask under single owner | Valid in host models / serialized init: requires spinlock if shared |
32-bit (528000000U * 18U) / frac | Narrow uint32_t ALU | Corrupts rate by -8.59 GHz wrap! | Silent-compile bug: 9,504,000,000 wraps 2^32 to 914,065,408 (38.08 MHz at /24) |
CCM_ANALOG_PFD_528(4) GL-E02 Quick Reference CCM_ANALOG_PFD_528(4) NAME CCM_ANALOG_PFD_480, CCM_ANALOG_PFD_528 - 4-lane phase-fractional dividers ADDRESSES PFD_480 / SET / CLR 0x020C80F0 / 0x020C80F4 / 0x020C80F8 (PLL3 480 MHz) PFD_528 / SET / CLR 0x020C8100 / 0x020C8104 / 0x020C8108 (PLL2 528 MHz) LANE LAYOUT (lane k in 0..3, shift s = 8 * k) [s+5:s] PFDk_FRAC 6-bit phase step in [12, 35] (mask = 0x3FU) [s+6] PFDk_STABLE read-only status; never write fabricated bits [s+7] PFDk_CLKGATE 1 = gated off, 0 = active clock output EQUATION F_pfdk = ((uint64_t)F_parent * 18U) / PFDk_FRAC Kernel Systems Academy Lesson 1.2 CCM_ANALOG_PFD_528(4) GL-E02 quick reference · full manual page: man 4 CCM_ANALOG_PFD_528 Check two subtle C11 bit-width rules in pll2_pfd2_set() below. First, FRAC occupies six bits (0x3FU, max 63, legal [12, 35]), not a 4-bit hex nibble (0x0FU): clearing only 0x0FU leaves old bits 4 and 5 stuck high! Second, when operating on Lane 3 (shift = 24U), the gate bit sits at bit 31 (24 + 7): always shift unsigned 1U << (shift + 7U) (or UINT32_C(1)), because signed 1 << 31 invokes Undefined Behavior in ISO C11. Finally, execute PFD2 updates only from internal OCRAM (0x00900000) or while MMDC is parked on an alternate source—never gate PLL2_PFD2 while fetching instructions from DDR3!
learner@ksa:~/gl-e02/m01-l02$ bat -H 7 -H 8 -H 9 -H 10 -H 11 -H 12 -H 13 target.c File: target.c /* Privileged OCRAM routine: MMDC/consumers already parked off PFD2. */ static int pll2_pfd2_set(unsigned int frac) { volatile unsigned int *pfd = (volatile unsigned int *)0x020c8100U; volatile unsigned int *set = (volatile unsigned int *)0x020c8104U; volatile unsigned int *clr = (volatile unsigned int *)0x020c8108U; const unsigned int shift = 16U; if (frac < 12U || frac > 35U) return -1; *set = 1U << (shift + 7U); *clr = 0x3fU << shift; *set = frac << shift; *clr = 1U << (shift + 7U); unsigned int budget = 1000000U; while (!(*pfd & (1U << (shift + 6U))) && --budget) { } return budget ? 0 : -1; }- Gate only PFD2 (bit 23) through the +0x04 SET command alias; PFD0, PFD1, and PFD3 keep running glitch-free.
- Clear all 6 fraction bits (0x3FU << 16) via CLR before setting the new 6-bit fraction via SET.
- Ungate PFD2 via CLR and poll read-only bit 22 (PFD2_STABLE) with a bounded timeout.
Proving 26-Bit Complement Preservation & 64-Bit Rational Bounds in C11
In m01_l02.c, we test both invariants on the host workstation. First, set_frac() updates Lane 2 ([21:16]) inside 0x605b585b to 24, and assert((old & ~mask) == (next & ~mask)) proves every single one of the other 26 bits (all three sibling bytes plus PFD2's own CLKGATE and STABLE bits) survived unchanged. Second, rate() promotes parent to uint64_t before * 18U, verifying exact 396 MHz (PLL2, FRAC=24) and 432 MHz (PLL3, FRAC=20) outputs plus exact floor bracketing q * 29 <= 9,504,000,000 < (q + 1) * 29 for non-integer FRAC = 29 (327,724,137 Hz).
learner@ksa:~/gl-e02/m01-l02$ bat -H 6 -H 10 -H 16 -H 17 -H 18 -H 19 -H 20 -H 21 -H 22 m01_l02.c File: m01_l02.c #include <assert.h> #include <stdint.h> #include <stdio.h> static uint32_t set_frac(uint32_t reg, unsigned lane, uint32_t frac) { assert(lane < 4U && frac >= 12U && frac <= 35U); unsigned shift = lane * 8U; return (reg & ~(UINT32_C(0x3f) << shift)) | (frac << shift); } static uint32_t rate(uint32_t parent, uint32_t frac) { assert(frac >= 12U && frac <= 35U); return (uint32_t)((uint64_t)parent * 18U / frac); } int main(void) { uint32_t old = UINT32_C(0x605b585b); uint32_t next = set_frac(old, 2U, 24U); uint32_t mask = UINT32_C(0x3f) << 16; assert((old & ~mask) == (next & ~mask)); assert(((next >> 16) & 63U) == 24U); assert(rate(528000000U, 24U) == 396000000U); assert(rate(480000000U, 20U) == 432000000U); uint32_t q = rate(528000000U, 29U); assert((uint64_t)q * 29U <= UINT64_C(9504000000)); assert((uint64_t)(q+1U) * 29U > UINT64_C(9504000000)); puts("PLL2_PFD2=396000000 PLL3_PFD=432000000 neighbors=preserved"); return 0; }- Unsigned UINT32_C(0x3f) << shift clears all 6 FRAC bits in the target byte while preserving 26 complement bits.
- Promote parent to uint64_t before * 18U so 528,000,000 * 18 (9.504e9) never wraps modulo 2^32.
- Bracket non-integer quotient q (FRAC=29) with q*29 <= N < (q+1)*29 to prove exact integer floor behavior.
Running the PFD Verifier & Silent-Bug Fault Injection
Build and run m01_l02.c below. Next, test both silent-compile bugs in a scratch copy: (1) narrow UINT32_C(0x3f) to 0x0fU and observe 0x58 retain bit 4 (56 instead of 24); (2) remove (uint64_t) inside rate() and observe rate(528000000U, 24U) compile cleanly with zero warnings yet compute 38,086,058 Hz instead of 396,000,000 Hz!
learner@ksa:~/gl-e02/m01-l02gcc -std=c11 -Wall -Wextra -Werror -O2 m01_l02.c -o m01_l02learner@ksa:~/gl-e02/m01-l02./m01_l02PLL2_PFD2=396000000 PLL3_PFD=432000000 neighbors=preservedlearner@ksa:~/gl-e02/m01-l02echo $?0learner@ksa:~/gl-e02/m01-l02learner@ksa:~/gl-e02/m01-l02strace -e trace=write,exit_group ./m01_l02write(1, "PLL2_PFD2=396000000 PLL3_PFD=432"..., 59) = 59exit_group(0) = ?+++ exited with 0 +++Common Production Pitfalls
warning: Symptom: Tuning PLL2_PFD0 in bare-metal C immediately locks up the board whenever the code executes out of external DDR3 (0x80000000), even though the identical function works in OCRAM (0x00900000). Root Cause: A whole-word write to CCM_ANALOG_PFD_528 (0x020C8100) temporarily gated or altered PFD2 ([23:16]), disrupting the MMDC DDR3 clock while Cortex-A7 was fetching instructions from DRAM. Fix: Modify only the target byte lane via PFD_528_SET (+0x04) and PFD_528_CLR (+0x08), and never gate PFD2 while MMDC depends on it.
warning: Symptom: 1 << (shift + 7) fails -Werror=shift-overflow on Lane 3 (shift = 24), or parent * 18U / frac computes ~38.1 MHz instead of 396 MHz. Root Cause: Signed literal 1 << 31 overflows 32-bit int, and 528000000U * 18U (0x2_367B_8800) truncates its top bits in 32-bit unsigned arithmetic before division. Fix: Use UINT32_C(1) << (shift + 7U) for bit masks and ((uint64_t)parent * 18U) / frac for every PFD frequency calculation.
Practice & Retrieval
Guided Practice: Setting PLL3_PFD3 to 454.7 MHz Safely
Configure PLL3_PFD3 (Lane 3, bits [31:24] of CCM_ANALOG_PFD_480 at 0x020C80F0, parent 480 MHz) to FRAC = 19. Step 1 (Rate & Regime): Compute ((uint64_t)480000000U * 18U) / 19U (8,640,000,000 / 19 = 454,736,842 Hz) and contrast it against FRAC = 15 (576 MHz step-up!). Step 2 (Lane 3 Masks): Write the exact SET/CLR operations using UINT32_C(1) << 31 for PFD3_CLKGATE and UINT32_C(0x3F) << 24 for PFD3_FRAC.
Independent Practice: Optimal PFD Pair Solver (pfd_solver.c)
Write a strict ISO C11 tool pfd_solver.c that sweeps FRAC across 12..35 on both PLL2 (528 MHz) and PLL3 (480 MHz) to find the (pll_id, frac, actual_hz) tuple minimizing |actual_hz - target_hz| without exceeding max_hz. Verify target_hz = 320000000U with max_hz = 330000000U (PLL3, FRAC = 27 -> 320,000,000 Hz exact!).
Key takeaways
PLL2(528 MHz) andPLL3(480 MHz) each drive four18-phasePFDbranches governed byF_pfd = ((uint64_t)parent * 18U) / FRACacrossFRACin[12, 35](withFRAC < 18stepping above the parent rate).- Each
32-bitPFDregister packs four8-bit lanes ([5:0]FRAC,[6]STABLERO,[7]CLKGATE); always mask all6fraction bits (0x3FU). - Use
+0x04 SETand+0x08 CLRhardware command offsets to update one gated byte lane without racing sibling peripherals, and never gatePLL2_PFD2while executing fromDDR3. 38,086,058 Hzinstead of396,000,000 Hz, because528000000U * 18U(9,504,000,000) wraps32-bituint32_tbefore/ 24U; promoteparenttouint64_tfirst.- Clear and insert with
~(UINT32_C(0x3f) << 16)and(24U << 16)(or+0x08CLR/+0x04SETaliases after gating bit23), touching only the6-bitPFD2_FRACfield. - Active consumers must already run from a live alternative parent (or execute from
OCRAM), because assertingCLKGATEstops output clock edges even whenFRACis valid. - In both
PFD_528_CLRandW1CGPIO1_ISR,1bits act as targeted clear commands while0bits are no-ops, so callers write(1U << bit)masks directly instead of|=. PLL3(480 MHzUSB1_PLL) divided by/6fixed prescaler gives80 MHz, then divided by(CSCDR1.UART_CLK_PODF + 1)(PODF = 0 -> /1 = 80 MHz).