@@ -537,35 +537,38 @@ bool HardwareSerial::setMode(SerialMode mode)
537
537
return uartSetMode (_uart, mode);
538
538
}
539
539
540
+ // minimum total RX Buffer size is the UART FIFO space (128 bytes for most SoC) + 1. IDF imposition.
540
541
size_t HardwareSerial::setRxBufferSize (size_t new_size) {
541
542
542
543
if (_uart) {
543
- log_e (" RX Buffer can't be resized when Serial is already running.\n " );
544
+ log_e (" RX Buffer can't be resized when Serial is already running. Set it before calling begin(). " );
544
545
return 0 ;
545
546
}
546
547
547
548
if (new_size <= SOC_UART_FIFO_LEN) {
548
- log_e (" RX Buffer must be higher than %d.\n " , SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
549
- return 0 ;
549
+ log_w (" RX Buffer set to minimum value: %d." , SOC_UART_FIFO_LEN + 1 ); // ESP32, S2, S3 and C3 means higher than 128
550
+ new_size = SOC_UART_FIFO_LEN + 1 ;
550
551
}
551
552
552
553
_rxBufferSize = new_size;
553
554
return _rxBufferSize;
554
555
}
555
556
557
+ // minimum total TX Buffer size is the UART FIFO space (128 bytes for most SoC).
556
558
size_t HardwareSerial::setTxBufferSize (size_t new_size) {
557
559
558
560
if (_uart) {
559
- log_e (" TX Buffer can't be resized when Serial is already running.\n " );
561
+ log_e (" TX Buffer can't be resized when Serial is already running. Set it before calling begin(). " );
560
562
return 0 ;
561
563
}
562
564
563
- if (new_size <= SOC_UART_FIFO_LEN) {
564
- log_e (" TX Buffer must be higher than %d.\n " , SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
565
- return 0 ;
565
+ if (new_size < SOC_UART_FIFO_LEN) {
566
+ log_w (" TX Buffer set to minimum value: %d." , SOC_UART_FIFO_LEN); // ESP32, S2, S3 and C3 means higher than 128
567
+ _txBufferSize = 0 ; // it will use just UART FIFO with SOC_UART_FIFO_LEN bytes (128 for most SoC)
568
+ return SOC_UART_FIFO_LEN;
566
569
}
567
-
568
- _txBufferSize = new_size;
569
- return _txBufferSize ;
570
+ // if new_size is SOC_UART_FIFO_LEN, _txBufferSize will be zero - just use the UART FIFO space
571
+ _txBufferSize = new_size - SOC_UART_FIFO_LEN; // for total correct report from "availableForWrite()" that matches a call to this function
572
+ return new_size ;
570
573
}
571
574
0 commit comments