From bca926eee227fa5acc1f82250f764179ad6d7458 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Mon, 12 Oct 2026 15:07:18 +0200 Subject: [PATCH] fix(serial): no 300 ms stall per frame with no USB host With the phone not connected, every frame (each packet heard, each advert) went to the USB port. With nobody holding it open the core either drops the bytes or lets its buffer fill, and streamWriteUntil() then spun out its whole timeout. Skip the write when the native USB Serial has no host. Co-Authored-By: Claude Opus 5.5 --- src/helpers/ArduinoSerialInterface.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/helpers/ArduinoSerialInterface.cpp b/src/helpers/ArduinoSerialInterface.cpp index 3e8cce3c..3c09b189 100644 --- a/src/helpers/ArduinoSerialInterface.cpp +++ b/src/helpers/ArduinoSerialInterface.cpp @@ -32,6 +32,13 @@ size_t ArduinoSerialInterface::writeFrame(const uint8_t src[], size_t len) { return 0; } + // A native USB port with no host holding it open: the core drops the bytes + // (nRF52 TinyUSB, ESP32 USBCDC) or lets its buffer fill, and either way + // streamWriteUntil() would spin out the whole timeout on every frame -- the + // loop stalled 300 ms per packet heard while no phone was connected. A UART + // bridge's Serial always reads true, so those boards are unaffected. + if (_serial == (Stream*)&Serial && !Serial) return 0; + uint8_t hdr[3]; hdr[0] = '>'; hdr[1] = (len & 0xFF); // LSB