@@ -103,7 +103,7 @@ void serialEventRun(void)
103
103
}
104
104
105
105
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 ) {}
107
107
108
108
void 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)
109
109
{
@@ -133,7 +133,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
133
133
}
134
134
#endif
135
135
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);
137
137
if (!baud) {
138
138
// using baud rate as zero, forces it to try to detect the current baud rate in place
139
139
uartStartDetectBaudrate (_uart);
@@ -147,7 +147,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
147
147
148
148
if (detectedBaudRate) {
149
149
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);
151
151
} else {
152
152
log_e (" Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible" );
153
153
_uart = NULL ;
@@ -268,3 +268,18 @@ void HardwareSerial::setPins(uint8_t rxPin, uint8_t txPin)
268
268
uartSetPins (_uart, rxPin, txPin);
269
269
}
270
270
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