@@ -103,7 +103,7 @@ void serialEventRun(void)
103103}
104104
105105
106- HardwareSerial::HardwareSerial (int uart_nr) : _uart_nr(uart_nr), _uart(NULL ) {}
106+ HardwareSerial::HardwareSerial (int uart_nr) : _uart_nr(uart_nr), _uart(NULL ), _rxBufferSize( 256 ) {}
107107
108108void HardwareSerial::begin (unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms, uint8_t rxfifo_full_thrhd)
109109{
@@ -133,7 +133,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
133133 }
134134#endif
135135
136- _uart = uartBegin (_uart_nr, baud ? baud : 9600 , config, rxPin, txPin, 256 , invert, rxfifo_full_thrhd);
136+ _uart = uartBegin (_uart_nr, baud ? baud : 9600 , config, rxPin, txPin, _rxBufferSize , invert, rxfifo_full_thrhd);
137137 if (!baud) {
138138 // using baud rate as zero, forces it to try to detect the current baud rate in place
139139 uartStartDetectBaudrate (_uart);
@@ -147,7 +147,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
147147
148148 if (detectedBaudRate) {
149149 delay (100 ); // Give some time...
150- _uart = uartBegin (_uart_nr, detectedBaudRate, config, rxPin, txPin, 256 , invert, rxfifo_full_thrhd);
150+ _uart = uartBegin (_uart_nr, detectedBaudRate, config, rxPin, txPin, _rxBufferSize , invert, rxfifo_full_thrhd);
151151 } else {
152152 log_e (" Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible" );
153153 _uart = NULL ;
@@ -268,3 +268,18 @@ void HardwareSerial::setPins(uint8_t rxPin, uint8_t txPin)
268268 uartSetPins (_uart, rxPin, txPin);
269269}
270270
271+ size_t HardwareSerial::setRxBufferSize (size_t new_size) {
272+
273+ if (_uart) {
274+ log_e (" RX Buffer can't be resized when Serial is already running.\n " );
275+ return 0 ;
276+ }
277+
278+ if (new_size <= SOC_UART_FIFO_LEN) {
279+ log_e (" RX Buffer must be higher than %d.\n " , SOC_UART_FIFO_LEN);
280+ return 0 ;
281+ }
282+
283+ _rxBufferSize = new_size;
284+ return _rxBufferSize;
285+ }
0 commit comments