From b472e821cf8957ba49e44b9fa7b688249bd3b7d5 Mon Sep 17 00:00:00 2001 From: mrkev-gh <122262981+mrkev-gh@users.noreply.github.com> Date: Mon, 6 Jan 2025 11:34:06 +0100 Subject: [PATCH] Use 75% of the buffer for speeds higher than 115200 (#22774) Higher speeds need larger buffer. Processing takes longer, so let's put the threshold at 75% of the buffer size to have some headroom. E.g. for 1Mbit with 2.5KB buffer 2048 characters would be roughly still around 20ms, and reserve additional 512 chars / 5ms to handle the buffer after the threshold is reached Co-authored-by: mrkev-gh --- lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp b/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp index 119b6d149..242aa5a99 100644 --- a/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp +++ b/lib/default/TasmotaSerial-3.6.0/src/TasmotaSerial.cpp @@ -172,10 +172,13 @@ void TasmotaSerial::Esp32Begin(void) { // At 19200, 120 chars are ~60ms // At 76800, 120 chars are ~15ms uart_set_rx_full_threshold(m_uart, 120); - } else { + } else if (m_speed == 115200) { // At 115200, 256 chars are ~20ms // Zigbee requires to keep frames together, i.e. 256 bytes max uart_set_rx_full_threshold(m_uart, 256); + } else { + // At even higher speeds set 75% of the buffer + uart_set_rx_full_threshold(m_uart, serial_buffer_size * 3 / 4); } // For bitrate below 115200, set the Rx time out to 6 chars instead of the default 10 if (m_speed < 115200) {