interpreters/berry: Fix raw console input#3632
Conversation
Use an opt-in NuttX console reader so Berry accepts CR, LF, and CRLF on raw CDC ACM consoles without sharing NSH history or completion state. Wire the reader into both Make and CMake builds while keeping the default fgets path unchanged. Signed-off-by: Frederick Blais <fred_blais5@hotmail.com>
c2c9a13 to
c5b332e
Compare
|
@speccy88 could you explain more why the process in serial driver framework doesn't work as expect? The basic process(\r, \n, DEL, BACK) should be handled by driver directly: |
|
Thanks for questioning the scope of this change. I retraced the reproducer and found that the behavior was real in my downstream Fruit Jam image, but the root cause was in that integration rather than in Berry or stock NuttX. My downstream NSH console patch configured the shared USB CDC descriptor with I have corrected the terminal lifecycle at the point where I introduced the regression in speccy88/NuttX-RP2350#4: the terminal remains canonical and echo-enabled for applications, while NSH readline temporarily takes byte-at-a-time/no-driver-echo ownership and restores the complete saved mode before launching a command. The Berry-specific reader has been removed downstream. This PR is therefore not pertinent to NuttX Apps, and I am closing it. Thank you for catching the scope problem before merge. For transparency, Codex (GPT-5) assisted with diagnosis, implementation, and review. I reviewed the result and remain responsible for the contribution. Future AI-assisted Apache commits from me will include the required |
Summary
Fix the Berry interactive console on raw NuttX terminals, including USB CDC ACM consoles that do not provide canonical input, CR-to-LF conversion, or driver echo.
The pinned Berry default port uses
fgets(). On a raw console, Enter commonly arrives as CR rather than LF, so the REPL andinput()wait indefinitely. Routing Berry through the shared NuttX readline implementation also leaks NSH history and tab completion into the interpreter.This change:
USE_NUTTX_CONSOLEreader to the pinned Berry source;The normal Berry
fgets()path remains unchanged whenUSE_NUTTX_CONSOLEis not defined.The equivalent source fix is also proposed upstream in berry-lang/berry#539. This local patch is needed for the Berry commit currently pinned by NuttX Apps.
Impact
input()work on raw serial and USB CDC terminals.system/readlineis not modified.Verification
Fruit Jam RP2350 hardware, minimal NuttX image over raw USB CDC ACM:
input()call.berry\r\n6*7\r\npreserves the first expression byte and evaluates to42.10+5evaluates to15with one following prompt.2+3evaluates to5.Build and local checks:
default/be_port.cblob:7d52aebe055b098febec472f32690c1ef71780e3.-Wall -Wextra -std=c99 -pedantic-errors -DUSE_NUTTX_CONSOLEpassed.sim:berryMake build passed;berry -e "print(6*7)"returned42.be_port.csuccessfully; the fullsim:berryCMake/Ninja path passed before the final hardware-only handoff addition.input()prompt flushing.git diff --checkpassed.checkpatch.shandcmake-formatpassed.