Skip to content

Reference: clarify Serial.setRxBufferSize description #7484

Closed
@wolfbert

Description

@wolfbert

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: ESP8266
  • Core Version: 2.7.2
  • Development Env: Arduino IDE
  • Operating System: Windows

Problem Description

https://arduino-esp8266.readthedocs.io/en/latest/reference.html#serial

Serial has additional 256-byte TX and RX buffers.

Looking at uart.cpp, I can only find support for the RX buffer.

The method Serial.setRxBufferSize(size_t size) allows to define the receiving buffer depth. The default value is 256.

While this reflects the code, it is by no means the whole story. The RX buffer shadows the hardware FIFO. If the RX buffer size is set to 0, UART initialization will fail. After every 16 (or more) received (unread) characters, FIFO content will be moved to the RX buffer which wraps around. So you can buffer at most RX buffer size + 15 (possibly up to 128) characters. Therefore, any change in the buffer size must be carefully considered. In case the buffer is resized smaller after UART initialization, unread data may get truncated (and the overrun flag remains unchanged).

As an aside, if the 128 byte hardware FIFO buffer is sufficient for the application, the RX buffer wouldn't be needed (but that requires a change in the code, i.e. don't allocate RX buffer unless requested size > 128).

Edit: fixed link to documentation.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions