Skip to content

grbllib: flush the output stream buffer on reset, not just the input buffer#988

Open
stevenrwood wants to merge 1 commit into
grblHAL:masterfrom
stevenrwood:fix/reset-write-buffer-not-flushed
Open

grbllib: flush the output stream buffer on reset, not just the input buffer#988
stevenrwood wants to merge 1 commit into
grblHAL:masterfrom
stevenrwood:fix/reset-write-buffer-not-flushed

Conversation

@stevenrwood

Copy link
Copy Markdown
Contributor

Summary

hal.stream.reset_read_buffer() is called on every reboot to clear pending input, but there was no equivalent call for the output side. reset_write_buffer is defined in the HAL stream interface (optional, documented for Modbus/RS-485 support) and at least one driver (Plugin_networking's telnetd.c) already implements it - but nothing in the core reboot sequence ever called it, on any transport.

Consequence: a stale, partially-transmitted TX message left in a driver's output buffer across a reset can leak out merged with the reboot's own output, with no separator - observed as a garbled/concatenated ALARM message (e.g. Alarm:-1 instead of a clean Alarm:3 - Reset/E-stop while in motion...) immediately following a Reset-during-motion repro.

Repro / verification

Reproduced identically on both Serial and Telnet on a Teensy 4.1 (iMXRT1062 driver) during a Reset-during-motion repro. After the fix, the ALARM: line prints cleanly on every repro attempt.

Fix

Call hal.stream.reset_write_buffer() (guarded, since it's optional per the HAL interface) right alongside the existing reset_read_buffer() call in the reboot sequence.

Test plan

  • Builds clean (Teensy 4.1 / PlatformIO)
  • Hardware-reproduced the corruption before the fix, and hardware-verified resolved after (identical on Serial and Telnet)

…buffer

hal.stream.reset_read_buffer() is called on every reboot to clear pending
input, but there was no equivalent call for the output side. reset_write_
buffer is defined in the HAL stream interface (optional, documented for
Modbus/RS-485 support) and at least one driver (Plugin_networking's
telnetd.c) already implements it - but nothing in the core reboot sequence
ever called it, on any transport.

Consequence: a stale, partially-transmitted TX message left in a driver's
output buffer across a reset can leak out merged with the reboot's own
output, with no separator - observed as a garbled/concatenated ALARM
message (e.g. "Alarm:-1" instead of a clean "Alarm:3 - ...") immediately
following a Reset-during-motion repro, reproduced identically on both
Serial and Telnet on a Teensy 4.1 (iMXRT1062 driver).

Fix: call hal.stream.reset_write_buffer() (guarded, since it's optional)
right alongside the existing reset_read_buffer() call in the reboot
sequence.
@terjeio

terjeio commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

The output buffer is not flushed to avoid garbled output so I need to be able to reproduce this myself.
BTW do you use ioSender and if so which version? Asking since it might be an issue with the sender.

@stevenrwood

stevenrwood commented Jul 19, 2026 via email

Copy link
Copy Markdown
Contributor Author

@stevenrwood

stevenrwood commented Jul 19, 2026 via email

Copy link
Copy Markdown
Contributor Author

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.

2 participants