Root clocks and safe ARM PLL switching
Start from the physics of crystal oscillators and synchronous CPU pipeline flip-flops, trace the i.MX6ULL CCM clock tree and 32-bit register bitfields, and retune ARM PLL1 to 528 MHz without ever dropping the Cortex-A7 clock.
What you'll learn
- Solve PLL1 and ARM root rates from encoded fields.
- Trace the safe-source handoff through a lock timeout.
- Diagnose why volatile does not establish analog readiness.
What a Hardware Clock Physically Does Inside a CPU
Before touching a single clock register, ask the foundational hardware question: what is a clock signal, and why does a processor freeze or crash the instant its clock misbehaves? Inside an ARM Cortex-A7 core, instructions do not flow continuously like water in a pipe. Instead, the datapath (Fetch -> Decode -> Execute -> Memory -> Writeback) alternates between clouds of combinational CMOS gates (decoders, shifters, 32-bit adders) and banks of edge-triggered D-flip-flop pipeline registers. While an adder computes r0 + r1, internal transistors switch at unequal speeds (t_comb), producing transient voltage hazards on intermediate wires. Pipeline flip-flops hide that chaos by ignoring their inputs throughout the cycle and latching a clean snapshot only at the rising voltage edge (0 V -> 1.1 V) of a periodic square wave—the hardware clock.
For every pipeline stage to latch valid bits rather than half-settled voltages, the time between two consecutive rising clock edges (T_clk = 1 / F_clk) must exceed the flip-flop clock-to-output delay (t_cq), the longest combinational logic path (t_comb), and the destination flip-flop setup window (t_setup): T_clk >= t_cq + t_comb + t_setup (at 528 MHz, T_clk is just 1.894 ns!). As Figure 1.1a illustrates, mutating an active clock violates this physical contract in two distinct ways. First, if software gates or disconnects the active clock (0 Hz), rising edges vanish completely—freezing the Cortex-A7 Instruction Fetch unit mid-routine so the core can never fetch the next instruction that would turn the clock back on. Second, if software rewrites an active multiplier in place or forgets a /2 divider (1056 MHz, T_clk = 0.947 ns), runt pulses narrower than t_comb + t_setup drive pipeline flip-flops into metastability, corrupting the Program Counter (PC) in nanoseconds.
Figure 1.1a. Synchronous pipeline physics — rising voltage edges latch settled ALU outputs when T_clk >= t_cq + t_comb + t_setup; stopping edges freezes fetch, while runt pulses corrupt state.
Why Silicon Uses One 24 MHz Crystal Plus Four Distinct Clock Circuits
Why not solder a 528 MHz crystal directly onto the circuit board? Fundamental-mode piezoelectric quartz crystals vibrate mechanically; cutting a quartz wafer thin enough to oscillate at 528 MHz would make it microscopically fragile and radiate severe electromagnetic interference (EMI) across board traces. Instead, our Cortex-A7 board mounts a rugged, temperature-stable 24 MHz quartz crystal (OSC24M, T = 41.67 ns), which feeds the i.MX6ULL clock-generation network (7 domain-specific PLLs rather than 7 interchangeable CPU oscillators). Inside the chip, four distinct building blocks transform that 24 MHz reference into every core and peripheral rate:
- Phase-Locked Loop (
PLL, insideCCM_ANALOGat0x020C8000): An analog-digital feedback control loop that multiplies frequency. A phase-frequency detector compares the24 MHzcrystal against a divided feedback tap of an analog Voltage-Controlled Oscillator (VCO), pumping charge onto a loop-filter capacitor until theVCOlocks at an exact multiple (F_pll1 = 24 MHz * DIV_SELECT / 2). Because charging that analog filter takes tens of microseconds, changingDIV_SELECTimmediately unlocks theVCOuntil hardware assertsLOCK(bit 31). - Glitchless Multiplexer (
Mux, insideCCMat0x020C4000): A digital selector switch (0or1) that chooses which upstream clock wire drives a downstream tree without generating runt pulses during the handoff (STEP_SELandPLL1_SW_CLK_SEL). - Post-Divider (
PODF): A synchronous digital counter that spaces rising edges out by an integer factor (divisor = field + 1), dividing1056 MHzby2(ARM_PODF = 1) down to528 MHz. - Clock Gate (
ENABLE/CCGR): An edge-alignedANDlatch that holds an unused branch flat so idle blocks burn zero dynamic switching power (P = C * V^2 * f).
mental model: Retuning the PLL that drives a live CPU is like servicing the main turbine of a hospital power plant: you must switch the building onto an already-running backup generator (24 MHz step_clk) before taking the turbine (PLL1) offline, and switch back only after its voltage and frequency stabilize (LOCK == 1).
Where it stops working: Unlike a mechanical transfer switch, multiplexers switch electronic edges in nanoseconds; software delay loops cannot prove analog lock or prevent over-speed setup-time violations without hardware status bits and barriers.
definition (Clock Control Module (CCM) & ARM PLL1): The digital Clock Control Module (CCM, 0x020C4000) houses glitchless parent multiplexers, integer post-dividers, and peripheral gates, while CCM_ANALOG (0x020C8000) houses the seven analog feedback PLLs (PLL1 ARM, PLL2 528 MHz System, PLL3 480 MHz USB1, PLL4 Audio, PLL5 Video, PLL6 Ethernet, and PLL7 USB2). For PLL1, PLL_ARM = 24 MHz * DIV_SELECT / 2 (DIV_SELECT in [54, 108], so DIV_SELECT = 88 yields 1056 MHz), while CCM_CCSR.STEP_SEL selects the 24 MHz crystal into step_clk and CCM_CCSR.PLL1_SW_CLK_SEL parks the downstream ARM path on step_clk during retuning.
Trace the complete hardware signal path in Figure 1.1b from left to right before reading any C code: notice how OSC24M splits into two parallel routes—an upper high-speed route through CCM_ANALOG_PLL_ARM (1056 MHz) and a lower always-live 24 MHz bypass route through STEP_SEL—which reconverge at the glitchless PLL1_SW_CLK_SEL switch ahead of CCM_CACRR (÷2 -> 528 MHz Cortex-A7).
Figure 1.1b. Complete i.MX6ULL ARM root clock schematic (top) and the seven domain-specialized PLLs driven by OSC24M (bottom).
Step through the four-stage handoff below to see how software keeps continuous clock edges flowing into the Cortex-A7 pipeline even if PLL1 fails to lock:
- Step 1. Step 1: Clear CCSR[8] (STEP_SEL = 0) so the 24 MHz crystal feeds the bypass input before switching roots.
- Step 2. Step 2: Set CCSR[2] (PLL1_SW_CLK_SEL = 1) + DSB/ISB so Cortex-A7 executes from live 24 MHz step_clk.
- Step 3. Step 3: Program CACRR (/2) and PLL_ARM (DIV_SELECT = 88), then poll read-only LOCK[31] under a finite budget.
- Step 4. Step 4: Once LOCK == 1, clear CCSR[2] + DSB/ISB to deliver 1056 MHz / 2 = 528 MHz to the ARM core.
Figure 1.1c. Never mutate PLL_ARM while PLL1_SW_CLK_SEL == 0; park on 24 MHz step_clk first and stay parked if LOCK times out.
Register Bitfields, Voltage Ordering & Safe Bare-Metal Sequencing
Inspect Figure 1.1c to map every bit slice software touches across CCM_ANALOG and CCM. In CCM_ANALOG_PLL_ARM (0x020C8000), bits [6:0] hold the 7-bit multiplier DIV_SELECT (legal range 54..108, yielding 648..1296 MHz at the PLL output), bit 13 (ENABLE) gates the PLL output buffer, bit 16 (BYPASS) routes a diagnostic reference around the VCO, and read-only bit 31 (LOCK) is driven high by the analog phase detector only after phase error settles. In CCM_CCSR (0x020C400C), bit 8 (STEP_SEL = 0) selects 24 MHz osc_clk and bit 2 (PLL1_SW_CLK_SEL = 1) switches the ARM tree onto step_clk. Downstream in CCM_CACRR (0x020C4010), ARM_PODF ([2:0]) encodes divisor - 1: writing 1 divides 1056 MHz by 1 + 1 = 2 to produce 528 MHz.
Figure 1.1c. Exact 32-bit bitfields for CCM_ANALOG_PLL_ARM, CCM_CCSR, and CCM_CACRR — always clear multi-bit fields (~0x7FU, ~7U) before bitwise OR.
| Clock Transition Strategy | Register Operations | Intermediate CPU Rate | Failure Boundary & Engineering Verdict |
|---|---|---|---|
Direct in-place PLL_ARM write | 1 store to 0x020C8000 | Unbounded VCO slew or 0 Hz | Broken: mutating the live clock stalls or glitches Cortex-A7 flip-flops |
Step-clock handoff + bounded LOCK poll | CCSR -> CACRR -> PLL_ARM -> CCSR (+ dsb/isb) | 24 MHz (12 MHz while PODF = 1) | Production standard: continuous edges + safe 24 MHz fallback on fault |
Unbounded while (!(PLL_ARM & LOCK)) | 4 MMIO writes without timeout | Stuck on step_clk forever if VCO fails | Unsafe in field: crystal/rail fault hangs boot silently with zero diagnostic log |
Toggling PLL_ARM.BYPASS (bit 16) alone | Analog bypass mux inside CCM_ANALOG | 24 MHz analog bypass path | Diagnostic only: does not exercise the glitchless digital CCSR switcher |
CCM_ANALOG_PLL_ARM(4) GL-E02 Quick Reference CCM_ANALOG_PLL_ARM(4) NAME CCM_CCSR, CCM_CACRR, CCM_ANALOG_PLL_ARM - Cortex-A7 root clock switch ADDRESSES CCM_CCSR 0x020C400C (STEP_SEL bit 8, PLL1_SW_CLK_SEL bit 2) CCM_CACRR 0x020C4010 (ARM_PODF bits [2:0], divisor = val + 1) CCM_ANALOG_PLL_ARM 0x020C8000 (DIV_SELECT [6:0], ENABLE 13, LOCK 31) EQUATIONS F_pll1 = F_osc24 * DIV_SELECT / 2 (valid DIV_SELECT: 54..108) F_arm = F_pll1 / (ARM_PODF + 1) (528 MHz at DIV=88, PODF=1) INVARIANTS 1. Route CPU to 24 MHz step_clk (PLL1_SW_CLK_SEL=1) + DSB/ISB first. 2. Poll LOCK (bit 31) with finite budget; stay on step_clk on timeout. Kernel Systems Academy Lesson 1.1 CCM_ANALOG_PLL_ARM(4) GL-E02 quick reference · full manual page: man 4 CCM_ANALOG_PLL_ARM Respect two hardware couplings alongside the register bits. First, frequency is coupled to core voltage (VDD_ARM_IN) and silicon speed grade: before raising F_arm (for instance from 396 MHz to 528 MHz or 792 MHz on industrial/consumer parts), raise and settle the regulator first; when lowering F_arm, reduce clock frequency before lowering voltage. Second, C's volatile keyword only prevents the compiler from caching MMIO loads in registers—it emits zero ARMv7-A synchronization instructions. Bracketing CCSR mux writes with dsb sy (Data Synchronization Barrier) and isb (Instruction Synchronization Barrier) ensures the store drains out of the CPU write buffer and flushes prefetched pipeline instructions before subsequent code touches PLL_ARM.
learner@ksa:~/gl-e02/m01-l01$ bat -H 8 -H 9 -H 10 -H 11 -H 12 -H 13 -H 14 target.c File: target.c /* ARMv7-A privileged BSP routine; VDD_ARM_IN already at >= 528 MHz OPP. */ #define REG32(a) (*(volatile unsigned int *)(a)) #define CCSR REG32(0x020c400cU) #define CACRR REG32(0x020c4010U) #define PLL_ARM REG32(0x020c8000U) static int arm_pll_528(void) { CCSR &= ~(1U << 8); /* STEP_SEL = 0 (24 MHz osc_clk) */ CCSR |= (1U << 2); /* PLL1_SW_CLK_SEL = 1 (step_clk) */ __asm__ volatile("dsb sy isb" : : : "memory"); CACRR = (CACRR & ~7U) | 1U; /* ARM_PODF = 1 => divide by 2 */ PLL_ARM = (PLL_ARM & ~127U) | 88U; /* DIV_SELECT = 88 => 1056 MHz */ unsigned int budget = 1000000U; while (!(PLL_ARM & (1U << 31)) && --budget) { } if (!budget) return -1; /* Fault: stay on 24 MHz step_clk! */ CCSR &= ~(1U << 2); /* Reconnect locked PLL1 */ __asm__ volatile("dsb sy isb" : : : "memory"); return 0; }- Park ARM_CLK_ROOT on the live 24 MHz step_clk and execute DSB/ISB before modifying CACRR or PLL_ARM.
- Poll read-only LOCK (bit 31) under a bounded budget; on timeout return -1 while keeping step_clk active so the CPU stays alive to log the fault.
Verifying the Handoff State Machine & 64-Bit Frequency Math on the Host
Dereferencing 0x020C400C inside a desktop Linux program would immediately fault in user-space virtual memory, yet we can—and should—verify the state-transition preconditions and 64-bit frequency arithmetic in strict ISO C11 before flashing bare-metal silicon. In m01_l01.c below, retune() refuses any multiplier change while c->step == 0 (CPU still running on PLL1) or when DIV_SELECT falls outside [54, 108], clears c->locked = 0 upon retuning, and reconnect() refuses to switch back unless c->locked == 1. Promoting UINT64_C(24000000) before multiplying guarantees intermediate products (1,056,000,000 Hz and higher) never overflow 32-bit arithmetic.
learner@ksa:~/gl-e02/m01-l01$ bat -H 6 -H 12 -H 24 -H 25 m01_l01.c File: m01_l01.c #include <assert.h> #include <stdint.h> #include <stdio.h> struct clock_path { int step, locked; uint32_t select, podf; }; static int retune(struct clock_path *c, uint32_t select) { if (!c->step || select < 54U || select > 108U) return -1; c->locked = 0; c->select = select; return 0; } static int reconnect(struct clock_path *c) { if (!c->locked) return -1; c->step = 0; return 0; } int main(void) { struct clock_path c = {0, 1, 66U, 1U}; assert(retune(&c, 88U) == -1); c.step = 1; assert(retune(&c, 88U) == 0); assert(reconnect(&c) == -1 && c.step); c.locked = 1; assert(reconnect(&c) == 0); uint64_t pll = UINT64_C(24000000) * c.select / 2U; uint64_t arm = pll / (c.podf + 1U); assert(pll == UINT64_C(1056000000)); assert(arm == UINT64_C(528000000)); puts("PLL1=1056000000 ARM=528000000 safe_transition=pass"); return 0; }- Reject retuning whenever c->step == 0 (unparked CPU) or DIV_SELECT lies outside the hardware [54, 108] lock range.
- Refuse switchback to PLL1 while c->locked == 0, keeping the modeled CPU safely on step_clk.
- Promote 24000000 to uint64_t via UINT64_C before multiplying so multi-gigahertz products never wrap.
Executing the Verifier & Fault-Injection Experiments
Compile and run m01_l01.c under -std=c11 -Wall -Wextra -Werror -O2. Confirm both the exact PLL1=1056000000 ARM=528000000 rates and exit status 0, then exercise the negative assertions by temporarily deleting if (!c->locked) return -1; inside reconnect() or passing 53U / 109U to retune() to see the state guards catch an unparked or unlocked transition immediately.
learner@ksa:~/gl-e02/m01-l01gcc -std=c11 -Wall -Wextra -Werror -O2 m01_l01.c -o m01_l01learner@ksa:~/gl-e02/m01-l01./m01_l01PLL1=1056000000 ARM=528000000 safe_transition=passlearner@ksa:~/gl-e02/m01-l01echo $?0learner@ksa:~/gl-e02/m01-l01learner@ksa:~/gl-e02/m01-l01strace -e trace=write,exit_group ./m01_l01write(1, "PLL1=1056000000 ARM=528000000 sa"..., 51) = 51exit_group(0) = ?+++ exited with 0 +++Timeout Recovery, Verification Provenance & OS Handoff
Look at why leaving PLL1_SW_CLK_SEL = 1 on timeout (return -1) is an architectural lifesaver rather than a cosmetic detail. At 24 MHz / 2 = 12 MHz, the Cortex-A7 runs 44x slower than 528 MHz, yet its pipeline flip-flops continue receiving clean, deterministic rising edges—allowing firmware to blink an error code or transmit a diagnostic frame instead of hanging dark. Just remember to notify rate-dependent subsystems (UART baud divisors or software delay loops) whenever fallback leaves the system on step_clk.
Separate three distinct layers of proof in your engineering log: (1) this host C11 run proves uint64_t divider math and state-guard ordering; (2) arm-none-eabi-objdump -d proves dsb sy and isb bracket both CCSR switches in compiled ARM machine code; and (3) target hardware sign-off reads back CCSR, CACRR, and PLL_ARM and measures divided CCM_CLKO1 on an oscilloscope. Once U-Boot 2025.x hands off to the Linux kernel 6.12 Common Clock Framework (drivers/clk/imx/clk-imx6ul.c), CCM becomes exclusive kernel-owned state—never poke raw 0x020C400C behind cpufreq. Later: Lesson m01-l02 moves to the fixed 528 MHz (PLL2) and 480 MHz (PLL3) system PLLs to synthesize eight fractional peripheral branches via 18 / PFD_FRAC.
Common Production Pitfalls
warning: Symptom: Execution freezes silently on the instruction immediately after writing CCM_ANALOG_PLL_ARM, with zero characters on UART1. Root Cause: PLL_ARM.DIV_SELECT was rewritten while CCM_CCSR.PLL1_SW_CLK_SEL remained 0 (CPU still clocked by PLL1), or CACRR.ARM_PODF was 0 (÷1), briefly driving the 528 MHz-rated core toward 1056 MHz. Fix: Always switch PLL1_SW_CLK_SEL = 1 (24 MHz step_clk) + dsb sy / isb first, set CACRR = 1 (÷2) before reconnecting PLL1, and wait for PLL_ARM.LOCK (bit 31) under a finite timeout.
warning: Symptom: Writing PLL_ARM |= 88U; produces DIV_SELECT = 122 (0x7A) instead of 88 (0x58), pushing the VCO above its specification ceiling. Root Cause: Bitwise |= merged 0x58 with prior 1 bits in DIV_SELECT[6:0] (such as reset 66 = 0x42: 0x42 | 0x58 = 0x7A) without clearing the 7-bit field mask first. Fix: Always clear the entire multi-bit field before inserting the new ratio: PLL_ARM = (PLL_ARM & ~0x7FU) | 88U; so ENABLE (bit 13) is preserved while old ratio bits clear to 0.
Practice & Retrieval
Guided Practice: Stepping Down to a 396 MHz Thermal-Throttle Point
Suppose board thermals require dropping Cortex-A7 from 528 MHz to 396 MHz while keeping CACRR.ARM_PODF = 1 (÷2). Step 1 (Solve Ratio): Solve 24 MHz * DIV_SELECT / 2 / 2 = 396 MHz for DIV_SELECT (hint: F_pll1 must equal 792 MHz, giving DIV_SELECT = 66, well inside [54, 108]). Step 2 (Sequence & Voltage): Write the exact four-step CCSR -> PLL_ARM -> LOCK -> CCSR sequence and state whether VDD_ARM_IN is lowered before or after the frequency reduction (lower frequency first, then voltage!).
Independent Practice: Speed-Grade Operating-Point Auditor (pll1_opp_audit.c)
Extend m01_l01.c into pll1_opp_audit.c accepting a silicon speed-grade ceiling (528000000U, 792000000U, or 900000000U). Sweep every (DIV_SELECT, ARM_PODF) pair across 54..108 and 0..7, rejecting any pair whose F_arm exceeds the speed-grade cap, and assert that (66, 1) -> 396 MHz passes on all grades while (99, 1) -> 594 MHz is rejected on 528 MHz silicon.
Key takeaways
- A hardware clock supplies periodic rising voltage edges that latch
Cortex-A7pipeline flip-flops after combinational logic settles (T_clk >= t_cq + t_comb + t_setup);0 Hzfreezes instruction fetch, while glitches cause metastability. - One
24 MHzcrystal drives seven specializedi.MX6ULLPLLs;PLL1multiplies24 MHz * DIV_SELECT / 2(88 -> 1056 MHz) ahead ofCACRR.ARM_PODF(field + 1, so1 -> ÷2 = 528 MHz). - Always park the core on
24 MHzstep_clk(CCSR.STEP_SEL = 0,CCSR.PLL1_SW_CLK_SEL = 1) withdsb syandisbbefore retuningPLL_ARM. - Poll read-only
PLL_ARM.LOCK(bit 31) under a finite timeout and remain onstep_clkwhenever lock fails. PLL1outputs1056 MHzvia24 MHz * DIV_SELECT / 2, andARM_PODF = 1divides by2to supply a528 MHzcore clock.- Return an error code while leaving
CCM_CCSR.PLL1_SW_CLK_SELset to1so theCortex-A7continues executing from the live24 MHzstep_clk. volatileonly prevents C compiler load/store elision; safe handoff still requiresdsb sy/isbordering barriers and boundedPLL_ARM.LOCKreadiness polling.- A CPU can execute
PLL1retuning instructions only while an independent live clock (24 MHzstep_clk) keeps driving its pipeline untilPLL_ARM.LOCKre-asserts. - Gate or park the
eLCDIFclock consumer first, programDIV_SELECT/NUM/DENOM, pollPLL_VIDEO.LOCK(bit 31) with a finite timeout, and refuse to enable scanout if lock times out.