Repository navigation
fix(teensy): tier-1 defensive hardening from 6-agent #3406 audit - #3407
Conversation
Two correctness fixes that the multi-agent audit flagged as plausible root causes for the residual 0.5-0.7 % byte corruption in #3406. Bench re-run showed Tier-1 alone does NOT measurably move the corruption rate, so the root cause must be elsewhere (Tier 2+ to follow). These fixes are still worth landing because they remove undefined-behavior hazards. 1. FlexPWM RX D-cache invalidate is now cache-line aligned (rx_flexpwm_channel.cpp.hpp::buildEdgeTimesFromCaptures). Previous call passed `captures_written * sizeof(u16)` -- arbitrary byte count -- to arm_dcache_delete. Cortex-M7 cache maintenance is only safe with 32-byte-aligned address + size; partial-line invalidate leaves 1-31 stale bytes adjacent to the region. New code rounds start address down and end address up to cache-line boundaries before calling arm_dcache_delete. 2. ObjectFLED::bitmaskLocal is now alignas(32) so its 16-byte arm_dcache_flush_delete in begin() operates on a single whole cache line rather than potentially straddling two partially. 3. FlexPWM capture-occurred flags (CAPTCOMPA/B bits 0:1 = CFA/CAE, CFB/CBE) are write-one-to-clear per i.MX RT1062 RM eFlexPWM chapter. Driver was writing 0 (no effect). Now writes 0x3 to actually clear them so a stale flag from a previous capture session can't produce a mismatched CVAL2/CVAL3 pair on the first read of the next session. Validation: - bash test --unit -> 254/254 passed - bash lint --cpp -> clean (PlatformIO-internal-usage warn-only) - bash autoresearch teensy41 --object-fled --tx-pin 22 --rx-pin 8 --timeout 60 --skip-lint, 3 consecutive runs: 0.4 %, 0.7 %, 0.5 % byte corruption (no regression from baseline ~0.5-0.7 %). Refs: #3406 #3359 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughTeensy 4.x RX capture now clears stale FlexPWM capture flags before starting and invalidates DMA capture buffers on 32-byte cache-line boundaries. The related ChangesTeensy RX capture cache correctness
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Tier-1 defensive correctness from the #3406 multi-agent audit
Two undefined-behavior hazards the audit identified — does NOT measurably move the 0.6 % byte corruption (verified empirically) but worth landing because both are genuine correctness fixes.
1. FlexPWM RX D-cache invalidate rounded to cache-line boundaries
arm_dcache_delete(mCaptureBuffer.data(), captures_written * sizeof(u16))was passed an arbitrary byte count. Cortex-M7 cache maintenance requires 32-byte-aligned address + size; a partial-line invalidate leaves 1-31 stale bytes adjacent. New code rounds start down + end up to cache-line boundaries.2.
ObjectFLED::bitmaskLocalisalignas(32)The 16-byte
arm_dcache_flush_deleteinbegin()now operates on a single whole cache line rather than potentially straddling two partially.3. CAPTCOMPA / CAPTCOMPB write-1-to-clear semantics
Per i.MX RT1062 RM eFlexPWM chapter,
CAPTCOMPA[CFA, CAE](bits 0:1) are write-1-to-clear capture-occurred flags. Driver was writing0which has no effect — a stale flag from a previous capture session could produce a mismatchedCVAL2/CVAL3pair on the first read of the next session. Now writes0x3to actually clear.Hardware result
Unchanged from baseline ~0.5-0.7 %. Root cause is in Tier 2 (decoder dual-phase validation) or Tier 3 (ISR memset scope / DMA priority) — to follow.
Test plan
bash test --unit→ 254/254 passedbash lint --cpp→ cleanRefs: #3406 #3359
🤖 Generated with Claude Code
Summary by CodeRabbit