Skip to content

Commit 0d24a48

Browse files
authored
Fixes (set RX/TX buffer size)
1 parent 8bb1a24 commit 0d24a48

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Diff for: cores/esp32/HardwareSerial.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -525,34 +525,37 @@ bool HardwareSerial::setMode(SerialMode mode)
525525
return uartSetMode(_uart, mode);
526526
}
527527

528+
// minimum total RX Buffer size is the UART FIFO space (128 bytes for most SoC) + 1. IDF imposition.
528529
size_t HardwareSerial::setRxBufferSize(size_t new_size) {
529530

530531
if (_uart) {
531-
log_e("RX Buffer can't be resized when Serial is already running.\n");
532+
log_e("RX Buffer can't be resized when Serial is already running. Set it before calling begin().");
532533
return 0;
533534
}
534535

535536
if (new_size <= SOC_UART_FIFO_LEN) {
536-
log_e("RX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
537-
return 0;
537+
log_w("RX Buffer set to minimum value: %d.", SOC_UART_FIFO_LEN + 1); // ESP32, S2, S3 and C3 means higher than 128
538+
new_size = SOC_UART_FIFO_LEN + 1;
538539
}
539540

540541
_rxBufferSize = new_size;
541542
return _rxBufferSize;
542543
}
543544

545+
// minimum total TX Buffer size is the UART FIFO space (128 bytes for most SoC).
544546
size_t HardwareSerial::setTxBufferSize(size_t new_size) {
545547

546548
if (_uart) {
547-
log_e("TX Buffer can't be resized when Serial is already running.\n");
549+
log_e("TX Buffer can't be resized when Serial is already running. Set it before calling begin().");
548550
return 0;
549551
}
550552

551553
if (new_size <= SOC_UART_FIFO_LEN) {
552-
log_e("TX Buffer must be higher than %d.\n", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
553-
return 0;
554+
log_w("TX Buffer set to minimum value: %d.", SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
555+
_txBufferSize = 0; // it will use just UART FIFO with SOC_UART_FIFO_LEN bytes (128 for most SoC)
556+
return SOC_UART_FIFO_LEN;
554557
}
555-
558+
// if new_size is higher than SOC_UART_FIFO_LEN, TX Ringbuffer will be active and it will be used to report back "availableToWrite()"
556559
_txBufferSize = new_size;
557560
return _txBufferSize;
558561
}

0 commit comments

Comments
 (0)