@@ -525,34 +525,37 @@ bool HardwareSerial::setMode(SerialMode mode)
525
525
return uartSetMode (_uart, mode);
526
526
}
527
527
528
+ // minimum total RX Buffer size is the UART FIFO space (128 bytes for most SoC) + 1. IDF imposition.
528
529
size_t HardwareSerial::setRxBufferSize (size_t new_size) {
529
530
530
531
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(). " );
532
533
return 0 ;
533
534
}
534
535
535
536
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 ;
538
539
}
539
540
540
541
_rxBufferSize = new_size;
541
542
return _rxBufferSize;
542
543
}
543
544
545
+ // minimum total TX Buffer size is the UART FIFO space (128 bytes for most SoC).
544
546
size_t HardwareSerial::setTxBufferSize (size_t new_size) {
545
547
546
548
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(). " );
548
550
return 0 ;
549
551
}
550
552
551
553
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;
554
557
}
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()"
556
559
_txBufferSize = new_size;
557
560
return _txBufferSize;
558
561
}
0 commit comments