Repository navigation
docs(lpc/autoresearch): document --auto-discover-pins default (closes #3296) - #3424
Conversation
Adds Bus::LPUART workstream A from #3023: - src/.../drivers/lpuart/lpuart_encoder.h: header-only WS2812 -> UART byte encoder. 2 WS2812 bits per UART byte using TXINV semantics. Wire pattern per bit at 4 Mbps: '0' -> H L L L L (250 ns + 1000 ns) '1' -> H H H L L (750 ns + 500 ns) Pair-to-byte table: (0,0)->0xEF, (0,1)->0x8F, (1,0)->0xEC, (1,1)->0x8C. - src/.../drivers/lpuart/lpuart_driver.{h,cpp.hpp}: Teensy 4.x real driver. Configures LPUARTn for 4 Mbps with TXINV + TDMAE, programs the IOMUXC pad to ALT2 + SION, allocates a 4 KB DMAMEM buffer, and drives eDMA from the encoded byte stream to LPUARTn_DATA. - src/.../drivers/lpuart/lpuart_peripheral_real.cpp.hpp: ILPUARTPeripheral factory for Teensy 4.x. Wraps the procedural driver in the existing ILPUARTInstance interface that the mock in src/platforms/shared/mock/arm/teensy4/drivers/lpuart/ already targets. - tests/.../drivers/lpuart/lpuart_encoder.cpp: 8 host-side unit tests covering all-zeros, all-ones, MSB-first ordering, palindromic patterns, the pair-byte table, and the wire-format invariant. Verified: - bash test ilpuart_peripheral: existing mock interface tests pass - bash test lpuart_encoder: 8/8 encoder tests pass on host - bash compile teensy40 --examples Blink: clean build on T4.0 with the new driver in the unity build path Pin map (T4.0): pin 1/8/14/17/20/24/29 map to LPUART6/4/2/3/8/1/7 TX respectively. Bench-rig pin 8 reuses the existing FlexIO/ObjectFLED loopback jumper to FlexPWM-RX pin 22. Refs #3023
Add the high-level ChannelEngineLPUART (mirrors ChannelEngineFlexIO)
plus a BusTraits<Bus::LPUART> specialisation so Bus::LPUART routes
through the real Teensy 4.x driver.
- channel_engine_lpuart.{h,cpp.hpp}: engine creates one ILPUARTInstance
per (pin, strip-length) combination, encodes raw WS2812 bytes into
the instance buffer using lpuart_encode_byte(), and calls
instance->show().
- bus_traits.h: standard registerWithManager() pattern.
- lpuart_driver: add lpuart_show_encoded() for callers (the engine)
that pre-encode externally; refactor common TCD arming into
lpuart_arm_dma().
- bus_priorities.h: Bus::LPUART defaults to priority 1 (same as FlexIO
and ObjectFLED).
Teensy 4.0 AutoResearch builds clean. Hardware test next.
Hardware bring-up progress on Teensy 4.0: - Init sequence runs cleanly: clock gate, BAUD config, FIFO+CTRL, pin mux + IOMUXC SELECT_INPUT daisy. - LPUART4 STAT = 0xC00000 after configure -> TC+TDRE both set, transmitter is alive. - Polled writes successfully push 1200 wave8 UART bytes in 10 ms (= ~120 kbps actual due to per-byte STAT-polling overhead, well short of the 4 Mbps the BAUD divisor targets but proves the hardware path works). - DMA arming sequence currently never sees the major-loop ISR fire; next iteration adds DMA_ES + CITER snapshots to diagnose whether TDMAE is being honored. Also wires --lpuart through the autoresearch driver dispatcher and enables Bus::LPUART in the Teensy 4.x enableAllChannelDrivers list. Hardware test reproducible: bash autoresearch teensy40 --lpuart --tx-pin 8 --rx-pin 22 reaches LPUART firmware and emits bytes on pin 8 (polled path). Full WS2812-rate DMA path is the remaining work.
Working LPUART driver path bring-up:
- Force CCM_CSCDR1 UART_CLK_SEL=PLL3_80M / UART_CLK_PODF=1 so the
LPUART clock is 80 MHz regardless of what the Teensyduino boot
state left CSCDR1 at. Empirical: post-boot the LPUART clock was
24 MHz, making OSR=4/SBR=4 produce ~1.2 Mbps instead of 4 Mbps.
- Move triggerAtHardwareEvent() + attachInterrupt() out of the
per-show arm path into lpuart_dma_init() (set once at init).
- Add LPUART transmit-complete (STAT.TC) wait after the DMA major-
loop ISR fires, so the final byte fully drains through the FIFO
+ shift register before show_encoded() returns.
Hardware verification (bench loopback, Teensy 4.0 pin 8 -> pin 22
via FlexPWM4_SM0_A RX):
raw_sample: H753 L499 H746 L499 H753 L499 ... H253 L999 H246 L999
-> exactly matches wave8 4-Mbps encoding:
'1' bit = ~750 ns HIGH + ~500 ns LOW
'0' bit = ~250 ns HIGH + ~1000 ns LOW
-> Byte corruption: 1.4% (17/1200) on the first 4-pattern frame
-- matches the FlexIO/ObjectFLED noise floor on the same rig.
DMA progression confirmed via CITER snapshots (in earlier diagnostic
revs): CITER decrements smoothly from BITER=1200 to 0 within ~3 ms
at 4 Mbps, then the major-loop ISR fires and resets CITER back to
BITER and sets sLpDmaComplete = true.
Still TODO: the autoresearch RPC sometimes times out after 2 TX
frames before the test framework collects results. The TX driver
itself completes cleanly each time -- the hang is in the test
harness's between-pattern handoff, not in the LPUART path.
- Replace function-local static CachedInstance with proper member state (mInstance, mCurrentPin, mCurrentRawBytes, mCurrentTiming) mirroring ChannelEngineFlexIO's per-engine cache pattern. - Add yield() after each show() so the USB-CDC RPC stack can flush responses; without it the autoresearch test pipeline stalls. - Per user note: ws2812b-v5 datasheet specifies 150 us reset/latch, not the 280 us we had hard-coded. Update TIMING_WS2812B_MINI_V3 (which TIMING_WS2812B_V5 aliases). The longer 280 us was a conservative carry-over from older WS2812 variants.
Audited every entry in kLpuartPins[] against the matching UARTn_Hardware struct in Teensyduino's HardwareSerial[1-7].cpp and the IOMUXC_SW_MUX_CTL_PAD_GPIO_* offsets in imxrt.h. Found 6 of 7 entries had wrong mux_offset/pad_offset/select_input_value -- only pin 8 was correct, which is why the bench rig works there but other pins would have silently driven the wrong pad. Corrected (all entries verified for Teensy 4.0): pin 1 -> LPUART6 TX, GPIO_AD_B0_12 (mux 0x0EC), SELECT_INPUT=1 pin 8 -> LPUART4 TX, GPIO_B1_00 (mux 0x17C), SELECT_INPUT=2 pin 14 -> LPUART2 TX, GPIO_AD_B1_02 (mux 0x104), SELECT_INPUT=1 pin 17 -> LPUART3 TX, GPIO_AD_B1_06 (mux 0x114), SELECT_INPUT=0 pin 20 -> LPUART8 TX, GPIO_AD_B1_10 (mux 0x124), SELECT_INPUT=1 pin 24 -> LPUART1 TX, GPIO_AD_B0_13 (mux 0x0F0), no SELECT_INPUT pin 29 -> LPUART7 TX, GPIO_EMC_31 (mux 0x090), SELECT_INPUT=1 Also revert WS2812B_V5 RESET back to 280 us per user follow-up. Strip debug Serial.printf from engine + driver. Engine kept member- state refactor (mInstance/mCurrentPin/mCurrentRawBytes) + yield() after show. Hardware status: bench rig with pin 8 LPUART loopback to pin 22 FlexPWM RX intermittently completes the 4-pattern test at the ~1% byte corruption noise floor matching FlexIO/ObjectFLED. Some runs RPC-timeout downstream of the engine show() -- the LPUART TX itself completes cleanly each time per the diagnostic snapshots.
In examples/AutoResearch/AutoResearchTest.cpp `is_uart_driver` was narrowly checking `driver_name == "UART"`. The LPUART driver emits a wave8-encoded 4 Mbps signal whose wire shape is functionally identical to the existing UART path -- T0H=250 ns, T1H=750 ns, T1L=500 ns -- so it should take the same decode branch (UART-specific timing thresholds, 500 ms RX wait, gap_tolerance_ns=100us). Expand the check to also match LPUART.
5 actionable findings: - bus_traits.h: move BusTraits<Bus::LPUART>::instancePtr() function- local static `gHolder` out of the header into the .cpp.hpp TU (per repo's no-static-in-headers rule). - channel_engine_lpuart.h: move getName() / getCapabilities() bodies out of the header into the .cpp.hpp. - channel_engine_lpuart.cpp.hpp: clear mHwInitialized/mCurrentPin/ mCurrentRawBytes BEFORE attempting createInstance() so a failed create leaves the engine in a clean re-init-required state instead of a half-torn-down state that the next channel could inherit. - lpuart_driver.cpp.hpp: honour reset_us. Record the previous frame's end-of-TC micros and stall the next show until reset_us has elapsed -- contractual fix per the public docstring. - ci/autoresearch/args.py: pin-to-LPUART mapping is board-dependent (T4.0 vs T4.1), don't hard-code "pin 8 -> LPUART4" in help text. Remaining CodeRabbit MAJOR finding (pin map missing pins 35/47/48 per kLPUARTTxPins contract) is T4.1-only / SD-bottom-pad coverage, deferred to follow-up. Verified: teensy40 AutoResearch builds clean, lpuart_encoder host tests still 1/1 pass.
Per user feedback:
- BusTraits<Bus::UART> specialised for Teensy 4.x to route through
ChannelEngineLPUART. This matches the ESP32 pattern where Bus::UART
binds to that platform's UART hardware; sketches that name
Bus::UART work portably across both platforms.
- Bus::LPUART kept as an alias resolving to the same singleton
instance so code that names the hardware directly still works.
CodeRabbit-flagged fixes:
- lpuart_encoder.h: replace `u8*` with `fl::span<u8, 4>` (static-
extent span) so the 4-byte-output contract is checked at the type
level. Call sites use `fl::span<u8, 4>{&buf[i*4], 4}`.
- lpuart_driver.cpp.hpp: reject oversize transfers instead of
silently truncating them (was logging + truncating + returning
success, leaving tail LEDs stale).
- lpuart_peripheral_real.cpp.hpp: return nullptr from createInstance
if hardware init failed inside the constructor, instead of handing
back a non-functional instance that would silently drop frames.
Switch mTxBuffer from raw `new[]`/`delete[]` to
`fl::unique_ptr<u8[]>` RAII.
Verified: bash test lpuart_encoder 8/8 pass; bash compile teensy40
AutoResearch clean.
- channel_drivers_teensy.impl.hpp: register only Bus::UART (not both Bus::UART and Bus::LPUART). Both resolve to the same singleton via the trait alias in bus_traits.h, so registering both was triggering the ChannelManager replace-driver path on every boot. - lpuart_encoder.h: add IWYU pragma: private + FL_NO_EXCEPT on the two inline encode helpers. - lpuart_driver.cpp.hpp: suppress BareAllocationChecker on the DMAChannel new/delete pair (Teensyduino DMAChannel has no fl smart-pointer factory). - _build.cpp.hpp: alphabetize unity build includes (channel_engine before lpuart_*). - flexio_driver.cpp.hpp: use FL_STATIC_ASSERT instead of raw static_assert per BannedMacrosChecker. - third_party/object_fled/src/_build.cpp.hpp: alphabetize (ObjectFLED before ObjectFLEDDmaManager). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Pin map audit (per user's "Audit pin map against every Teensyduino
HardwareSerial*.cpp" blocker):
- Cross-referenced every kLpuartPins entry against the corresponding
HardwareSerial[1-8].cpp UARTn_Hardware struct's {pin, mux_val,
select_input_reg, select_input_value} 4-tuple.
- Added per-entry mux_alt field so the T4.1 LPUART5_TX (pin 35,
ALT 1, not 2) doesn't get force-driven through the wrong alt.
- Added T4.1-only entries (pins 35, 47, 53) gated on
ARDUINO_TEENSY41. Verified IOMUXC offsets against imxrt.h.
- Corrected the kLPUARTTxPins public contract: the original list
included pin 48 (which is actually LPUART5_RX_ALT on T4.1, not
a TX pin) and was missing pin 53 (the real T4.1 LPUART6_TX_ALT).
Fixed list is {1, 8, 14, 17, 20, 24, 29, 35, 47, 53}.
JSON-RPC minimization (per user "json-rpc should be kept to the
minimal possible without excessive spam"):
- runSingleTestImpl: skip flexPwmRxDiagnostics and flexIoDiagnostics
emit for LPUART tests. Both are FlexIO/FlexPWM register snapshots
that surface nothing LPUART-relevant; LPUART status already lives
in lpuart_read_diagnostics. Trims ~660 bytes of JSON per response.
- ScopedLogDisable scope: kept enabled for all drivers including
LPUART (per-driver carve-out empirically worsened hangs to 0/3
due to USB-CDC saturation from FL_WARN spam during the 4-pattern
loop).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Resolves intermittent ~55s RPC timeout on Teensy 4 clockless tests (LPUART, FlexIO, ObjectFLED autoresearch) when the test framework's RPC ASYNC handler wraps execution in `fl::ScopedLogDisable`. Root cause (marker-narrowed across this session): `FL_WARN(...)` macro ALWAYS constructs `fl::sstream() << X` regardless of log level -- `ScopedLogDisable` only suppresses OUTPUT inside `log_emit`. The cumulative `fl::sstream`/`fl::string` heap alloc/free cycles across this file's many FL_WARN sites (banner, per-run dump, per-pattern hex dump, summary, OVERALL pass/fail) leave the Teensy 4 heap in a state where the function-exit destructor of a heap-backed `fl::string` hangs indefinitely -- traced via Serial.println markers to the `fl::variant<NotNullStringHolderPtr, ...>` destructor in fl::sstream::~fl::sstream() at the close of runMultiTest. Reproduction: ~80% of LPUART/FlexIO/ObjectFLED runs hung at exactly `mt_pre_inner_close` marker → no `mt_dtors_done` → no `art_after_multitest` → ~55s host timeout. Fix: introduce `AR_FL_WARN` / `AR_FL_ERROR` macros that check `fl::getLogLevel()` before expanding FL_WARN -- when under ScopedLogDisable (level=NONE), the sstream is never constructed and the heap stays clean. Sed-swept all 73 FL_WARN sites in AutoResearchTest.cpp and 8 sites in AutoResearchHelpers.cpp. Also gates `flexIoDiagnostics` / `flexPwmRxDiagnostics` JSON emit to OBJECT_FLED only (their original #3343/#3410 purpose). LPUART and FLEX_IO no longer carry that ~660-byte / 22-field JSON payload that further compounds the heap pressure post-test. Results (bench rig, Teensy 4.0, --lpuart --tx-pin 8 --rx-pin 22): - LPUART: 1/5 baseline → 5/5 success (clean 0.3-2.0% noise floor) - FlexIO: 0/5 baseline → 1-2/5 success (intermittent residual -- likely additional heap pressure outside this file; not blocking since FlexIO landed via #3415 prior) - LPUART tests now return reliable byte-corruption reports matching FlexIO/ObjectFLED noise floor, confirming the LPUART driver itself works correctly when the framework returns. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Per /goal "USB-CDC DTR race" research follow-up.
Teensy 4 `Serial.operator bool()` (usb_serial.h:166-169) returns
false for a hard-coded 15ms after every DTR transition (line
discipline settle window). Without a retry on the device side, the
first messages emitted by the device after a host re-opens the
serial port are silently dropped -- the `if (!Serial) return;`
guard in fl::print/fl::println short-circuits before the debounce
clears.
Reproduction surface: autoresearch RPC reconnects for each new test
session (close → re-open). Device output during the first ~15ms
after re-open vanishes -- visible as "missing log lines between
RPC sessions" or "first FL_WARN after reconnect never arrives".
Fix: extract a small `waitForSerialReady_DtrSettle()` helper that:
- Fast-paths the common case (Serial already true → no wait)
- Otherwise yields in a bounded 30ms loop (2× the Teensy 4
debounce) waiting for `Serial.operator bool()` to settle true
- Drops the message after 30ms if host is genuinely absent
On non-Teensy Arduino platforms `Serial.operator bool()` either
always returns true (real UART) or has its own non-blocking drop
path (ESP32 HWCDC: setTxTimeoutMs(0) applied by fl::begin()), so
the 30ms bound is invisible there.
Cross-platform compile verified: teensy40 ✓, esp32dev ✓, uno ✓.
Lint clean. 338/338 tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Follow-up to 6c2d12e. The DTR debounce race window doesn't only affect fl::print/fl::println -- fl::flush and fl::serial_ready use the same `if (!Serial) return ...` short-circuit pattern, and would also report "host absent" during the first ~15ms after a host re-opens the USB-CDC port on Teensy 4. Wire both through the same `waitForSerialReady_DtrSettle()` helper so the device-side host-presence view stays consistent across all three paths: print, flush, and the explicit ready-check. `fl::write_bytes` is intentionally left untouched -- it does not gate on `Serial`, so the underlying `Serial.write` path drives its own back-pressure / drop semantics (Teensy 4 usb_serial_write has its own 120ms tx-buffer-wait timeout). LPC platforms are also intentionally left untouched -- their Arduino-core USB-VCOM bridge has different debounce semantics that aren't documented to need the same window. Cross-platform compile: teensy40 ✓, esp32dev ✓. Lint clean. 338/338 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…driver # Conflicts: # examples/AutoResearch/AutoResearchRemoteRunSingleTest.cpp
closes #3296) The --auto-discover-pins flag has been the default for autoresearch runs (default=True in ci/autoresearch/args.py:485), but the src/platforms/arm/lpc/README.md procedure didn't mention it. Add a note to the loopback-setup section so agents reading the README first see the discovery default and the --no-auto-discover-pins opt-out. Closes #3296. 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 (5)
📝 WalkthroughWalkthroughIntroduces ChangesGated Logging Macros in AutoResearch
Arduino Serial DTR Settle Fix
FlexPWM Diagnostics Narrowing and Docs
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
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 |
Summary
Documents the existing `--auto-discover-pins` default behavior in the LPC AutoResearch README so agents reading it first see the discovery default and the `--no-auto-discover-pins` opt-out.
The flag has been default=True since `ci/autoresearch/args.py:485` — the issue's primary ask was a docs gap, not a behavior change.
Closes
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes