8000 Fix Serial RX and add option for FIFO Full Threshold in Serial.begin · Jason2866/arduino-esp32@371f382 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 371f382

Browse files
committed
Fix Serial RX and add option for FIFO Full Threshold in Serial.begin
Fixes: espressif#5005
1 parent 425619d commit 371f382

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

cores/esp32/HardwareSerial.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ HardwareSerial Serial2(2);
5050

5151
HardwareSerial::HardwareSerial(int uart_nr) : _uart_nr(uart_nr), _uart(NULL) {}
5252

53-
void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t txPin, bool invert, unsigned long timeout_ms)
53+
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)
5454
{
5555
if(0 > _uart_nr || _uart_nr > 2) {
5656
log_e("Serial number is invalid, please use 0, 1 or 2");
@@ -78,7 +78,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
7878
txPin = TX2;
7979
}
8080
#endif
81-
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert);
81+
_uart = uartBegin(_uart_nr, baud ? baud : 9600, config, rxPin, txPin, 256, invert, rxfifo_full_thrhd);
8282
_tx_pin = txPin;
8383
_rx_pin = rxPin;
8484

@@ -94,7 +94,7 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
9494

9595
if(detectedBaudRate) {
9696
delay(100); // Give some time...
97-
_uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, 256, invert);
97+
_uart = uartBegin(_uart_nr, detectedBaudRate, config, rxPin, txPin, 256, invert, rxfifo_full_thrhd);
9898
} else {
9999
log_e("Could not detect baudrate. Serial data at the port must be present within the timeout for detection to be possible");
100100
_uart = NULL;

cores/esp32/HardwareSerial.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class HardwareSerial: public Stream
5555
public:
5656
HardwareSerial(int uart_nr);
5757

58-
void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL);
58+
void begin(unsigned long baud, uint32_t config=SERIAL_8N1, int8_t rxPin=-1, int8_t txPin=-1, bool invert=false, unsigned long timeout_ms = 20000UL, uint8_t rxfifo_full_thrhd = 112);
5959
void end();
6060
void updateBaudRate(unsigned long baud);
6161
int available(void);

cores/esp32/esp32-hal-tinyusb.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ typedef struct {
4848
bool external_phy;
4949
} tinyusb_config_t;
5050

51-
static TaskHandle_t s_tusb_tskh;
52-
5351
static void configure_pins(usb_hal_context_t *usb)
5452
{
5553
for (const usb_iopin_dsc_t *iopin = usb_periph_iopins; iopin->pin != -1; ++iopin) {
@@ -74,7 +72,6 @@ static void configure_pins(usb_hal_context_t *usb)
7472

7573
esp_err_t tinyusb_driver_install(const tinyusb_config_t *config)
7674
{
77-
int res;
7875
log_i("Driver installation...");
7976

8077
// Hal init

cores/esp32/esp32-hal-uart.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ static void ARDUINO_ISR_ATTR _uart_isr(void *arg)
130130
}
131131
}
132132

133-
void uartEnableInterrupt(uart_t* uart)
133+
static void uartEnableInterrupt(uart_t* uart, uint8_t rxfifo_full_thrhd)
134134
{
135135
UART_MUTEX_LOCK();
136-
uart->dev->conf1.rxfifo_full_thrhd = 112;
136+
uart->dev->conf1.rxfifo_full_thrhd = rxfifo_full_thrhd;
137137
#if CONFIG_IDF_TARGET_ESP32
138138
uart->dev->conf1.rx_tout_thrhd = 2;
139139
#else
@@ -149,7 +149,7 @@ void uartEnableInterrupt(uart_t* uart)
149149
UART_MUTEX_UNLOCK();
150150
}
151151

152-
void uartDisableInterrupt(uart_t* uart)
152+
static void uartDisableInterrupt(uart_t* uart)
153153
{
154154
UART_MUTEX_LOCK();
155155
uart->dev->conf1.val = 0;
@@ -162,7 +162,7 @@ void uartDisableInterrupt(uart_t* uart)
162162
UART_MUTEX_UNLOCK();
163163
}
164164

165-
void uartDetachRx(uart_t* uart, uint8_t rxPin)
165+
static void uartDetachRx(uart_t* uart, uint8_t rxPin)
166166
{
167167
if(uart == NULL) {
168168
return;
@@ -171,25 +171,25 @@ void uartDetachRx(uart_t* uart, uint8_t rxPin)
171171
uartDisableInterrupt(uart);
172172
}
173173

174-
void uartDetachTx(uart_t* uart, uint8_t txPin)
174+
static void uartDetachTx(uart_t* uart, uint8_t txPin)
175175
{
176176
if(uart == NULL) {
177177
return;
178178
}
179179
pinMatrixOutDetach(txPin, false, false);
180180
}
181181

182-
void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted)
182+
static void uartAttachRx(uart_t* uart, uint8_t rxPin, bool inverted, uint8_t rxfifo_full_thrhd)
183183
{
184184
if(uart == NULL || rxPin >= GPIO_PIN_COUNT) {
185185
return;
186186
}
187187
pinMode(rxPin, INPUT);
188-
uartEnableInterrupt(uart);
188+
uartEnableInterrupt(uart, rxfifo_full_thrhd);
189189
pinMatrixInAttach(rxPin, UART_RXD_IDX(uart->num), inverted);
190190
}
191191

192-
void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted)
192+
static void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted)
193193
{
194194
if(uart == NULL || txPin >= GPIO_PIN_COUNT) {
195195
return;
@@ -198,7 +198,7 @@ void uartAttachTx(uart_t* uart, uint8_t txPin, bool inverted)
198198
pinMatrixOutAttach(txPin, UART_TXD_IDX(uart->num), inverted, false);
199199
}
200200

201-
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted)
201+
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted, uint8_t rxfifo_full_thrhd)
202202
{
203203
if(uart_nr >= UART_PORTS_NUM) {
204204
return NULL;
@@ -256,7 +256,7 @@ uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rx
256256
UART_MUTEX_UNLOCK();
257257

258258
if(rxPin != -1) {
259-
uartAttachRx(uart, rxPin, inverted);
259+
uartAttachRx(uart, rxPin, inverted, rxfifo_full_thrhd);
260260
}
261261

262262
if(txPin != -1) {
@@ -322,7 +322,11 @@ uint32_t uartAvailable(uart_t* uart)
322322
if(uart == NULL || uart->queue == NULL) {
323323
return 0;
324324
}
325+
#ifdef UART_READ_RX_FIFO
325326
return (uxQueueMessagesWaiting(uart->queue) + uart->dev->status.rxfifo_cnt) ;
327+
#else
328+
return uxQueueMessagesWaiting(uart->queue);
329+
#endif
326330
}
327331

328332
uint32_t uartAvailableForWrite(uart_t* uart)
@@ -333,6 +337,7 @@ uint32_t uartAvailableForWrite(uart_t* uart)
333337
return 0x7f - uart->dev->status.txfifo_cnt;
334338
}
335339

340+
#ifdef UART_READ_RX_FIFO
336341
void uartRxFifoToQueue(uart_t* uart)
337342
{
338343
uint8_t c;
@@ -357,17 +362,20 @@ void uartRxFifoToQueue(uart_t* uart)
357362
uart->dev->int_clr.val = 0xffffffff;
358363
UART_MUTEX_UNLOCK();
359364
}
365+
#endif
360366

361367
uint8_t uartRead(uart_t* uart)
362368
{
363369
if(uart == NULL || uart->queue == NULL) {
364370
return 0;
365371
}
366372
uint8_t c;
373+
#ifdef UART_READ_RX_FIFO
367374
if ((uxQueueMessagesWaiting(uart->queue) == 0) && (uart->dev->status.rxfifo_cnt > 0))
368375
{
369376
uartRxFifoToQueue(uart);
370377
}
378+
#endif
371379
if(xQueueReceive(uart->queue, &c, 0)) {
372380
return c;
373381
}
@@ -380,10 +388,12 @@ uint8_t uartPeek(uart_t* uart)
380388
return 0;
381389
}
382390
uint8_t c;
391+
#ifdef UART_READ_RX_FIFO
383392
if ((uxQueueMessagesWaiting(uart->queue) == 0) && (uart->dev->status.rxfifo_cnt > 0))
384393
{
385394
uartRxFifoToQueue(uart);
386395
}
396+
#endif
387397
if(xQueuePeek(uart->queue, &c, 0)) {
388398
return c;
389399
}

cores/esp32/esp32-hal-uart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extern "C" {
5151
struct uart_struct_t;
5252
typedef struct uart_struct_t uart_t;
5353

54-
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted);
54+
uart_t* uartBegin(uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t queueLen, bool inverted, uint8_t rxfifo_full_thrhd);
5555
void uartEnd(uart_t* uart, uint8_t rxPin, uint8_t txPin);
5656

5757
uint32_t uartAvailable(uart_t* uart);

0 commit comments

Comments
 (0)
0