Lab 1: CCM Clock-Tree Handoff, PFD Lane Masks & Bus-Divider Verifier

65 minfree previewLinux 6.12C11U-Boot 2025.01← module 1

Calculate parent and root frequencies, preserve unrelated register fields, and reject unsafe clock transitions.

Prerequisites in this module

What ./check.sh verifies

  • lab_m01_ccm_pll_tree (recorded value/5 passed; first failure -> recorded value) " recorded value recorded value.
step 1/15

step 1/15 · inspect starter files and specification

Early ARMv7-A board bring-up frequently fails before a single character reaches UART1 because clock-initialization code mutates CCM_ANALOG_PLL_ARM (0x020C8000) while PLL1 is still clocking the Cortex-A7 pipeline, overwrites sibling byte lanes inside CCM_ANALOG_PFD_528 (0x020C8100), or computes 528,000,000 * 18 / PFD_FRAC inside 32-bit unsigned arithmetic where 9,504,000,000 wraps silently modulo 2^32 to 914,065,408. In this studio lab, you will diagnose two seeded silent-compile clock bugs in starter/, repair the PLL1 step-clock state guard and 64-bit PFD boundary verifier, and validate AHB/IPG/PERCLK root dividers under TAP version 13.

learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01ls -lastarter/Makefilestarter/boundary.cstarter/checks.hstarter/lab.cstarter/m01_l01.cstarter/m01_l02.cstarter/m01_l03.clearner@ksa:~/gl-e02/lab-m01
starter: starter/Makefile
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/Makefile File: starter/Makefile    CC = gcc    CFLAGS = -std=c11 -Wall -Wextra -Werror -O2    all: lab    lab: lab.o boundary.o m01_l01.o m01_l02.o m01_l03.o    	$(CC) $(CFLAGS) $^ -o $@    lab.o: lab.c checks.h    	$(CC) $(CFLAGS) -c $< -o $@    boundary.o: boundary.c checks.h    	$(CC) $(CFLAGS) -c $< -o $@    m01_l01.o: m01_l01.c checks.h    	$(CC) $(CFLAGS) -Dmain=m01_l01_check -c $< -o $@    m01_l02.o: m01_l02.c checks.h    	$(CC) $(CFLAGS) -Dmain=m01_l02_check -c $< -o $@    m01_l03.o: m01_l03.c checks.h    	$(CC) $(CFLAGS) -Dmain=m01_l03_check -c $< -o $@    clean:    	rm -f *.o lab    .PHONY: all clean
starter: starter/boundary.c
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/boundary.c File: starter/boundary.c    #include <assert.h>    #include <stdint.h>    #include "checks.h"    static int pfd(uint32_t n, uint32_t *out) {        /* BUG 2: off-by-one lower bound (11U) and 32-bit numerator overflow! */        if (n < 11U || n > 35U) return -1;        *out = (528000000U * 18U) / n;        return 0;    }    int boundary_check(void) {        uint32_t out = 7U;        assert(pfd(0U, &out) == -1 && out == 7U);        assert(pfd(11U, &out) == -1 && pfd(36U, &out) == -1);        for (uint32_t n = 12U; n <= 35U; ++n) {            assert(pfd(n, &out) == 0);            assert((uint64_t)out * n <= UINT64_C(528000000) * 18U);            assert((uint64_t)(out + 1U) * n > UINT64_C(528000000) * 18U);        }        return 0;    }
starter: starter/checks.h
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/checks.h File: starter/checks.h    #ifndef GL_E02_CHECKS_H    #define GL_E02_CHECKS_H    int m01_l01_check(void);    int m01_l02_check(void);    int m01_l03_check(void);    int boundary_check(void);    #endif
starter: starter/lab.c
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/lab.c File: starter/lab.c    #define _POSIX_C_SOURCE 200809L    #include <fcntl.h>    #include <stdint.h>    #include <stdio.h>    #include <stdlib.h>    #include <string.h>    #include <time.h>    #include <unistd.h>    #include "checks.h"        static int cmp_double(const void *a, const void *b) {        double da = *(const double *)a;        double db = *(const double *)b;        return (da > db) - (da < db);    }        static int run_benchmark(void) {        enum { WARMUP = 5, SAMPLES = 35, LOOPS = 100 };        double us[SAMPLES];        fflush(stdout);        int saved_out = dup(STDOUT_FILENO);        int devnull = open("/dev/null", O_WRONLY);        if (saved_out < 0 || devnull < 0) return EXIT_FAILURE;        if (dup2(devnull, STDOUT_FILENO) < 0) return EXIT_FAILURE;        close(devnull);            int rc = 0;        for (int s = -WARMUP; s < SAMPLES; ++s) {            struct timespec t0, t1;            clock_gettime(CLOCK_MONOTONIC, &t0);            for (int k = 0; k < LOOPS; ++k) {                if (m01_l01_check() != 0) rc = 1;                if (m01_l02_check() != 0) rc = 1;                if (m01_l03_check() != 0) rc = 1;                if (boundary_check() != 0) rc = 1;            }            clock_gettime(CLOCK_MONOTONIC, &t1);            fflush(stdout);            if (s >= 0) {                double sec = (double)(t1.tv_sec - t0.tv_sec);                double nsec = (double)(t1.tv_nsec - t0.tv_nsec);                us[s] = sec * 1e6 + nsec * 1e-3;            }        }            fflush(stdout);        if (dup2(saved_out, STDOUT_FILENO) < 0) return EXIT_FAILURE;        close(saved_out);        if (rc != 0) return EXIT_FAILURE;            qsort(us, SAMPLES, sizeof(us[0]), cmp_double);        printf("bench_samples=%d warmup=%d loops_per_sample=%d p50_us=%.2f p95_us=%.2f p99_us=%.2f\n",               SAMPLES, WARMUP, LOOPS, us[17], us[33], us[34]);        return EXIT_SUCCESS;    }        int main(int argc, char **argv) {        if (argc != 2) return EXIT_FAILURE;        if (strcmp(argv[1], "--bench") == 0) return run_benchmark();        if (strcmp(argv[1], "1") == 0) return m01_l01_check();        if (strcmp(argv[1], "2") == 0) return m01_l02_check();        if (strcmp(argv[1], "3") == 0) return m01_l03_check();        if (strcmp(argv[1], "4") == 0) return boundary_check();        return EXIT_FAILURE;    }
starter: starter/m01_l01.c
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/m01_l01.c File: starter/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) {        /* BUG 1: switches CCSR back to PLL1 without verifying PLL_ARM.LOCK! */        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;    }
starter: starter/m01_l02.c
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/m01_l02.c File: starter/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;    }
starter: starter/m01_l03.c
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat starter/m01_l03.c File: starter/m01_l03.c    #include <assert.h>    #include <stdint.h>    #include <stdio.h>    static int wait_busy(unsigned clear_after, unsigned budget) {        for (unsigned n = 0U; n < budget; ++n)            if (n >= clear_after) return 0;        return -1;    }    int main(void) {        uint32_t ahb_field = 3U, ipg_field = 1U, per_field = 23U;        uint32_t ahb = 528000000U / (ahb_field + 1U);        uint32_t ipg = ahb / (ipg_field + 1U);        uint32_t per = 24000000U / (per_field + 1U);        assert(ahb == 132000000U && ipg == 66000000U);        assert(per == 1000000U);        assert(528000000U / (0U + 1U) == 528000000U);        assert(wait_busy(0U, 4U) == 0);        assert(wait_busy(3U, 4U) == 0);        assert(wait_busy(4U, 4U) == -1);        assert(wait_busy(0U, 0U) == -1);        puts("AHB=132000000 IPG=66000000 PERCLK=1000000 timeout=detected");        return 0;    }

step 2/15 · 2. learning objectives

  1. Enforce safe CCM_CCSR step-clock sequencing (STEP_SEL = 0, PLL1_SW_CLK_SEL = 1) so PLL1 reconnection is rejected whenever PLL_ARM.LOCK (bit 31) is unasserted.
  2. Isolate 6-bit PFD_FRAC updates (0x3FU << (8 * lane)) inside packed 32-bit PFD_528/PFD_480 words without disturbing PFD_STABLE, PFD_CLKGATE, or neighboring PFD0..PFD3 lanes.
  3. Verify uint64_t PFD rational arithmetic across every legal fraction 12..35 while rejecting out-of-range divisors 0..11 and 36+ prior to division.
  4. Measure multi-translation-unit clock-tree verification throughput (p50/p95/p99) with CLOCK_MONOTONIC.

step 3/15 · 3. environment requirements

  • Tested Host Environment: Linux 7.0.0-42-generic (x86_64, POSIX user space) running inside labs/lab_m01_ccm_pll_tree/.
  • Target Silicon Alignment (Cortex-A7): All C11 translation units enforce fixed-width <stdint.h> types (uint32_t, uint64_t) so 32-bit ARMv7 EABI (arm-none-eabi-gcc) and 64-bit x86_64 hosts produce identical PLL1 (528 MHz), PLL2_PFD2 (396 MHz), AHB (132 MHz), IPG (66 MHz), and PERCLK (1 MHz) results.

step 4/15 · 4. required software & hardware

  • Software: gcc (-std=c11 -Wall -Wextra -Werror -O2), GNU make, POSIX /bin/sh, and GNU Binutils (nm, objdump).
  • Hardware: Standard Linux workstation (0 root privileges or physical JTAG probes required for the 5 automated checks; oscilloscope probing on CCM_CLKO1 applies during optional physical board sign-off).

step 5/15 · 5. complete executable commands

Execute the workflow below from labs/lab_m01_ccm_pll_tree/ to observe the failing starter/ baseline, inspect each individual invariant case, benchmark execution latency, and verify the repaired reference build:

learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat script.sh File: script.sh    # 1. Run check.sh against starter/ to reproduce the two seeded clock-tree failures    sh check.sh starter        # 2. Build starter/ in isolation and inspect which assertion aborts in check 2 and check 5    make -B -C starter    ./starter/lab 1 ; echo "case1_rc=$?"    ./starter/lab 4 ; echo "case4_rc=$?"        # 3. Build the clean reference implementation in files/ and inspect linked object symbols    make -B -C files    nm -g files/lab | grep '_check$'        # 4. Run all four individual clock-tree verification cases (PLL1, PFD lanes, AHB/IPG/PERCLK, PFD sweep)    ./files/lab 1 && ./files/lab 2 && ./files/lab 3 && ./files/lab 4        # 5. Collect 35-sample CLOCK_MONOTONIC latency percentiles (after 5 warmup iterations)    ./files/lab --bench        # 6. Execute the authoritative 5-check TAP version 13 gate    sh check.sh

*Command rationale:* sh check.sh starter compiles starter/ in a temporary sandbox to expose silent-compile defects without mutating your working tree; ./starter/lab 1 and ./starter/lab 4 isolate the PLL1 lock-bypass and PFD 32-bit overflow failures; nm -g confirms -Dmain=m01_l0X_check symbol renaming across translation units; and sh check.sh confirms 5/5 TAP checks exit 0.

step 6/15 · 6. annotated source code (`starter/` flaws vs `files/` reference)

Seeded Defects in starter/

  1. Unlocked PLL1 Reconnection (starter/m01_l01.c): reconnect() clears c->step = 0 unconditionally without checking if (!c->locked) return -1;. On Cortex-A7 hardware, clearing CCM_CCSR.PLL1_SW_CLK_SEL after a PLL_ARM.LOCK timeout routes an unlocked or stopped VCO directly into ARM_CLK_ROOT, freezing instruction fetch before any diagnostic can run.
  2. Off-By-One PFD_FRAC Range & 32-Bit Numerator Wrap (starter/boundary.c): pfd() checks if (n < 11U || n > 35U) (accepting illegal PFD_FRAC = 11, which would attempt 864 MHz out of a 528 MHz parent!) and evaluates (528000000U * 18U) / n in 32-bit uint32_t, wrapping 9,504,000,000 down to 914,065,408 (38,086,058 Hz at n = 24 instead of 396,000,000 Hz!).

Verified Repairs in files/

  • files/m01_l01.c: Enforces if (!c->step || select < 54U || select > 108U) return -1; in retune(), enforces if (!c->locked) return -1; in reconnect(), and widens UINT64_C(24000000) * c.select / 2U before applying c.podf + 1U.
  • files/m01_l02.c: Masks ~(UINT32_C(0x3f) << shift) inside byte lane lane * 8U so sibling lanes and bits 7:6 (CLKGATE, STABLE) remain bit-for-bit identical ((old & ~mask) == (next & ~mask)).
  • files/m01_l03.c: Decodes AHB_PODF = 3 (/4 -> 132 MHz), IPG_PODF = 1 (/2 -> 66 MHz), and CSC1_PERCLK_PODF = 23 from the 24 MHz oscillator (/24 -> 1 MHz) while rejecting clear_after == budget in wait_busy().
  • files/boundary.c: Enforces n < 12U || n > 35U, computes UINT64_C(528000000) * 18U / n, and proves out * n <= 9,504,000,000 < (out + 1) * n across all 24 legal fractions.

step 7/15 · 7. expected output

learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat listing.txt File: listing.txt    $ sh check.sh starter    TAP version 13    1..5    ok 1 - Strict C11 build from source    not ok 2 - PLL1 safe-source transition and output rate      ---      diagnostic: "Guard reconnect() on c->locked != 0 so CCM_CCSR stays on 24 MHz step_clk until PLL1 locks"      ...    ok 3 - PFD lane isolation and exact frequency    ok 4 - AHB IPG PERCLK encoded dividers    not ok 5 - PFD extremes and rejected zero divisor      ---      diagnostic: "Reject PFD_FRAC outside [12, 35] and use UINT64_C(528000000) * 18U to prevent 32-bit wrap"      ...    # pass 3/5    FAIL: lab_m01_ccm_pll_tree (3/5 passed; first failure -> check 2 (PLL1 safe-source transition and output rate): Guard reconnect() on c->locked != 0 so CCM_CCSR stays on 24 MHz step_clk until PLL1 locks)        $ ./files/lab --bench    bench_samples=35 warmup=5 loops_per_sample=100 p50_us=12.34 p95_us=12.43 p99_us=12.44        $ sh check.sh    TAP version 13    1..5    ok 1 - Strict C11 build from source    ok 2 - PLL1 safe-source transition and output rate    ok 3 - PFD lane isolation and exact frequency    ok 4 - AHB IPG PERCLK encoded dividers    ok 5 - PFD extremes and rejected zero divisor    # pass 5/5

step 8/15 · 8. explanation of observed behavior

When sh check.sh starter runs, check 1 passes (ok 1) because both seeded bugs are 100% valid ISO C11 with zero compiler warnings under -Wall -Wextra -Werror. Check 2 (not ok 2) aborts on assert(reconnect(&c) == -1 && c.step) because retune(&c, 88U) cleared c.locked = 0 and starter's reconnect() switched c.step back to 0 anyway. Check 5 (not ok 5) aborts on assert(pfd(11U, &out) == -1 ...) and would otherwise fail the rational bracket out * n <= 9,504,000,000 due to 32-bit modular wraparound (9,504,000,000 mod 2^32 = 914,065,408). Once both invariants are restored in files/, all 5 TAP checks pass (# pass 5/5).

step 9/15 · 9. experiment variations

  1. PERCLK Parent-Mux Drift (m01_l03.c): Change per from 24000000U / (per_field + 1U) (CSCMR1.PERCLK_CLK_SEL = 1, oscillator) to ipg / (per_field + 1U) (66 MHz / 24 = 2.75 MHz) and observe check 4 fail, demonstrating why EPIT/GPT drivers must inspect parent muxes rather than divider numbers alone.
  2. Nibble-Mask Corruption (m01_l02.c): Narrow UINT32_C(0x3f) to UINT32_C(0x0f) in set_frac() when old lane 2 holds 0x58 (FRAC = 24, bit 6 STABLE = 1), then update to 15: bit 4 (16) survives, leaving FRAC = 31 (306.58 MHz instead of 480 MHz!).
  3. Undefined-Behavior Sanitizer Audit: Run make -B -C files CFLAGS="-std=c11 -Wall -Wextra -Werror -O1 -g -fsanitize=undefined" and verify ./files/lab 1..4 produce zero UBSan traps.

step 10/15 · 10. performance measurements

Measured on the Linux 7.0.0-42-generic build host using CLOCK_MONOTONIC across 5 warmup runs and 35 timed samples (100 full 4-suite iterations per sample):

Benchmark MetricMeasured Host (x86_64 Linux 7.0.0-42-generic)Target Cortex-A7 @ 528 MHz Expectation
100x full clock-tree 4-check suite (p50 / p95 / p99)12.34 us / 12.43 us / 12.44 us~180 - 420 us (pure integer register/SRAM math)
Physical PLL1 relock time (CCM_ANALOG_PLL_ARM.LOCK)Modeled state flag (0 ns analog wait)~60 - 250 us crystal-to-VCO phase convergence
CCM_CDHIPR.AHB_PODF_BUSY synchronizationBounded 4-step state test~3 - 12 destination AHB clock cycles (< 1 us)

step 11/15 · 11. troubleshooting

SymptomRoot CauseFix
not ok 2 (reconnect(&c) == -1 assertion fails)reconnect() clears c->step without checking c->lockedAdd if (!c->locked) return -1; before c->step = 0; in m01_l01.c
not ok 5 (pfd(11U, &out) returns 0 or wrong out)n < 11U bound or 32-bit 528000000U * 18U wraparoundReject `n < 12U \\n > 35U and multiply with UINT64_C(528000000) * 18U`
Neighbor PFD lanes change during set_frac()Whole-word write or inverted clear mask (reg & (0x3fU << s))Use `(reg & ~(UINT32_C(0x3f) << shift)) \(frac << shift)`
multiple definition of 'main' during makeLesson .c compiled without -Dmain=m01_l0X_checkCompile each lesson object via $(CC) $(CFLAGS) -Dmain=$*_check -c

step 12/15 · 12. guided questions

  1. Why can PLL2 (528 MHz) produce a PFD output faster than 528 MHz without containing another multiplier stage?
  • *Hint 1:* Evaluate F_pfd = 528 MHz * 18 / PFD_FRAC across the legal lower range PFD_FRAC = 12..17.
  • *Hint 2:* Count how many phase taps (18) the PLL2 ring oscillator exposes per 528 MHz reference period (1.894 ns / 18 = 105.2 ps tap spacing).
  1. Why does target code execute dsb sy and isb immediately after CCSR |= (1U << 2) before writing PLL_ARM?
  • *Hint 1:* Can an out-of-order/buffered MMIO store to CCM_ANALOG_PLL_ARM (0x020C8000) reach the analog wrapper while the CCM_CCSR mux (0x020C400C) store is still draining?
  • *Hint 2:* What does isb guarantee for instructions fetched into the Cortex-A7 pipeline after the clock-parent mux switches?

step 13/15 · 13. independent challenges

  1. Near Transfer — PLL3 (480 MHz) PFD0..PFD3 Table & Tolerance Finder: Add int best_pfd_frac(uint32_t parent_hz, uint32_t max_hz, uint32_t target_hz, uint32_t *frac_out, int64_t *ppm_err) that searches frac in 12..35, rejects any candidate exceeding max_hz, and picks the closest legal fraction in signed parts-per-million (ppm) using 64-bit integer math (0 double operations).
  2. Far Transfer — Transactional Clock-Tree Dependency Validator: Model a struct clk_tree connecting OSC24, PLL1, PLL2, PLL2_PFD2, AHB, IPG, and PERCLK. Implement int clk_reparent_safe(struct clk_tree *t, ...) that refuses to gate PLL2_PFD2 whenever MMDC_ACTIVE is flagged as a live consumer, preventing self-inflicted DDR3 fetch lockups.

step 14/15 · 14. solutions & explanations

  • Guided Question 1: Stepping fewer than 18 phase taps per output period (PFD_FRAC in 12..17) synthesizes output periods shorter than 1 / 528 MHz (up to 528 * 18 / 12 = 792 MHz at PFD_FRAC = 12), so software must check each downstream peripheral's maximum input frequency before selecting small fractions.
  • Guided Question 2: dsb sy stalls execution until the posted CCSR write completes on the IPS peripheral bus, and isb flushes the Cortex-A7 instruction pipeline so subsequent PLL_ARM writes execute only after step_clk is actively clocking the core.
  • Challenge 1 Key Formula: Compute cand_hz = (UINT64_C(18) * parent_hz) / frac (skipping if cand_hz > max_hz), then rank exact rational error via |18 * parent_hz - target_hz * frac| * 1,000,000 / (target_hz * frac) in int64_t.

step 15/15 · run verification and inspect output

Run the verification command and confirm the output matches the expected contract.

learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01./starter/lab 1 ; echo "case1_rc=$?"learner@ksa:~/gl-e02/lab-m01
expected output
TAP version 131..5ok 1 - Strict C11 build from source

Progressive hints & solution

hint 1

Compare starter/Makefile against the module lessons. Focus first on: lab_m01_ccm_pll_tree (recorded value/5 passed; first failure -> recorded value) " recorded value recorded value.

hint 2

Compile with -std=c11 -Wall -Wextra -Werror, check every system-call return value before touching output buffers, and verify cleanup on error paths.

solution

Run the check

From labs/lab_m01_ccm_pll_tree/, run ./check.sh. A complete solution emits TAP version 13 with every test point marked ok and exits 0:

./check.sh — lab m01
learner@ksa:~/gl-e02/lab-m01./check.shTAP version 131..5ok 1 - Strict C11 build from sourceok 2 - PLL1 safe-source transition and output rateok 3 - PFD lane isolation and exact frequencyok 4 - AHB IPG PERCLK encoded dividersok 5 - PFD extremes and rejected zero divisor# pass 5/5

On an incomplete starter tree, ./check.sh exits non-zero and marks the unmet assertion not ok with an indented YAML diagnostic block:

./check.sh — lab m01 (starter)
learner@ksa:~/gl-e02/lab-m01./check.shTAP version 131..5ok 1 - Strict C11 build from sourcenot ok 2 - PLL1 safe-source transition and output rate  ---  diagnostic: "Guard reconnect() on c->locked != 0 so CCM_CCSR stays on 24 MHz step_clk until PLL1 locks"  ...ok 3 - PFD lane isolation and exact frequencyok 4 - AHB IPG PERCLK encoded dividersnot ok 5 - PFD extremes and rejected zero divisor  ---  diagnostic: "Reject PFD_FRAC outside [12, 35] and use UINT64_C(528000000) * 18U to prevent 32-bit wrap"  ...# pass 3/5FAIL: lab_m01_ccm_pll_tree (3/5 passed; first failure -> check 2 (PLL1 safe-source transition and output rate): Guard reconnect() on c->locked != 0 so CCM_CCSR stays on 24 MHz step_clk until PLL1 locks)

note: How to read TAP diagnostics: 1..N states the total test plan; each ok k confirms a passed check; not ok k pinpoints the failing check alongside message: (what went wrong) and hint: (where to look next) between --- and ....

inspect harness: check.sh
learner@ksa: ~/gl-e02/lab-m01
learner@ksa:~/gl-e02/lab-m01$ bat check.sh File: check.sh    #!/bin/sh    set -u    cd "$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"    src_dir="${1:-files}"    if [ ! -d "$src_dir" ]; then        printf "TAP version 13\n1..1\nnot ok 1 - missing directory %s\nFAIL: %s missing source directory %s\n" "$src_dir" "lab_m01_ccm_pll_tree" "$src_dir"        exit 1    fi    work=$(mktemp -d "$PWD/.check.XXXXXX") || exit 1    trap 'rm -rf "$work"' EXIT HUP INT TERM    cp -R "$src_dir" "$work/build"    printf 'TAP version 13\n1..5\n'    pass=0    first_fail=""    report() {        if [ "$1" -eq 0 ]; then            printf 'ok %s - %s\n' "$2" "$3"            pass=$((pass + 1))        else            printf 'not ok %s - %s\n' "$2" "$3"            printf '  ---\n  diagnostic: "%s"\n  ...\n' "$4"            if [ -z "$first_fail" ]; then                first_fail="check $2 ($3): $4"            fi        fi    }    make -B -C "$work/build" >"$work/build.log" 2>&1    report "$?" 1 "Strict C11 build from source" "Ensure all translation units compile cleanly under gcc -std=c11 -Wall -Wextra -Werror"    "$work/build/lab" 1 >"$work/case1.log" 2>&1    report "$?" 2 "PLL1 safe-source transition and output rate" "Guard reconnect() on c->locked != 0 so CCM_CCSR stays on 24 MHz step_clk until PLL1 locks"    "$work/build/lab" 2 >"$work/case2.log" 2>&1    report "$?" 3 "PFD lane isolation and exact frequency" "Mask only 0x3fU << shift in set_frac() and promote parent to uint64_t before * 18U"    "$work/build/lab" 3 >"$work/case3.log" 2>&1    report "$?" 4 "AHB IPG PERCLK encoded dividers" "Decode AHB_PODF, IPG_PODF, and PERCLK_PODF as (field + 1U) with strict < budget busy polling"    "$work/build/lab" 4 >"$work/case4.log" 2>&1    report "$?" 5 "PFD extremes and rejected zero divisor" "Reject PFD_FRAC outside [12, 35] and use UINT64_C(528000000) * 18U to prevent 32-bit wrap"    printf "# pass %s/5\n" "$pass"    if [ "$pass" -ne 5 ]; then        printf "FAIL: lab_m01_ccm_pll_tree (%s/5 passed; first failure -> %s)\n" "$pass" "$first_fail"        exit 1    fi    exit 0

Definition of done

Verification checklist

status: 0/3 checks verified

Troubleshooting

Compiler fails under -Werror on sign conversion or unused args

Use exact POSIX return types (ssize_t for read()/write(), size_t for byte counts) rather than relaxing flags.

./check.sh reports missing files in files/

Invoke ./check.sh from inside labs/lab_m01_ccm_pll_tree/ so relative paths to files/ resolve directly.

Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure