Skip to content

Keep firmware autonomous during host UART loss - #585

Merged
DRSDavidSoft merged 4 commits into
mainfrom
fix/firmware-host-disconnect-freeze
Oct 1, 2026
Merged

DRSDavidSoft merged 4 commits into
mainfrom
fix/firmware-host-disconnect-freeze

Conversation

@DRSDavidSoft

@DRSDavidSoft DRSDavidSoft commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #584.

Root cause

The firmware UART service had drained HardwareSerial until available() reached zero since the initial firmware commit. A removed or noisy USB-UART bridge can keep adding input, monopolizing the MCU loop and starving autonomous keys, relays, displays, LEDs, audio, telemetry, and completion of the watchdog-supervised loop.

Fix

  • snapshot the ATmega328P UART ring occupancy on entry and drain only that bounded set
  • leave bytes arriving during the pass for the next cooperative firmware loop
  • preserve incremental framing across calls, including maximum-size frames
  • add native regression coverage for sustained noise, delimiter recovery, and multi-pass frame processing

Verification

  • focused UART protocol CTest: passed
  • complete VirtualBoard/firmware CTest: 19/19 passed before the size-only refinement
  • full AVR firmware compile through project Controller tooling: passed
  • default full profile retained: hosted CI reports 32,248 / 32,384 application bytes
  • optional EEPROM-menu-label profile compiles locally without disabling any feature; estimated SRAM margin 280 bytes
  • live control case before code change: host serial closed for 8 seconds and reconnected without watchdog reset, distinguishing normal handle close from physical/noisy adapter loss

No Go build/test was run in this pass.

Copilot AI balanced review requested due to automatic review settings October 1, 2026 17:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The bounded receive loop addresses UART starvation while retaining framing behavior and targeted regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Bounds UART receive work to keep firmware services responsive during noisy or failed host connections.

Changes:

  • Limits each UART service pass to 32 bytes and handles failed reads.
  • Preserves incremental frame parsing across service calls.
  • Adds regression coverage for noise, read failures, and recovery.
File Description
Project/​UartProtocol.cpp Implements bounded, failure-aware UART reads.
Project/​UartProtocol.h Defines the receive-byte budget.
Tools/​VirtualBoard/​tests/​uart_protocol_test.cpp Tests bounded processing and recovery.
Tools/​VirtualBoard/​tests/​arduino_mock/​Arduino.h Adds simulated serial read failures.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The bounded processing logic is consistent with AVR ring behavior and has focused regression coverage.

Review effort: Balanced
Findings: None

@DRSDavidSoft
DRSDavidSoft merged commit 82bc064 into main Oct 1, 2026
25 checks passed
@DRSDavidSoft
DRSDavidSoft deleted the fix/firmware-host-disconnect-freeze branch October 1, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix firmware freeze when host serial connection disconnects

3 participants