Skip to content

Possible regression of serial communication performance since version 2.x #7505

Closed
@awawa-dev

Description

@awawa-dev

Board

ESP32 dev module

Device Description

Board capable of 2Mb serial speed (CH9102x)

Hardware Configuration

nothing is connected

Version

v2.0.5

IDE Name

Arduino IDE, PlatformIO

Operating System

Windows, Linux

Flash frequency

default

PSRAM enabled

no

Upload speed

default

Description

As of version 2.x I observe possible performance regression compared to version 1.x when high-speed communication is used (2 000 000 baud). We verify the integrity of the frame data to make sure the frame is complete and undamaged.

Simplified sketch and python test client provided as an attachment. 'Esp32 dev module' with CH9102x

With version 1.0.6 was working fine.
image

Sending 900 bytes frames without any problem to ESP32 board. The reception is confirmed.

image

Since version 2.x the same sketch does not work anymore, which was first reported by our users and then confirmed by us after testing. We are unable to maintain such communication, all 900 byte frames are damaged or incomplete:

image

None of 900 byte frames is receive undamaged and completed.

image

It starts to work for ~600 byte frame but with high error rate:

image
client_and_sketch.zip

Sketch

Test client and sketch provided as an attachment in the description section.

Debug Message

not applicable since it's not a bug

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Activity

VojtechBartoska

VojtechBartoska commented on Nov 25, 2022

@VojtechBartoska
Contributor

Hello @awawa-dev, thanks for the issue.

I'm tagging @SuGlider who did bunch of improvements to Serial recently.

SuGlider

SuGlider commented on Nov 26, 2022

@SuGlider
Collaborator

@awawa-dev - Please turn on Log messages (Core Debug Level: "Verbose") in the Arduino IDE.
You shall see this message:
RX Buffer can't be resized when Serial is already running.

Change your setup() to:

void setup()
{
	Serial.setRxBufferSize(MAX_BUFFER);  // before begin()
	Serial.begin(COM_SPEED);
	
	Serial.setTimeout(50);
        Serial.write("Hello tester!");
}
awawa-dev

awawa-dev commented on Nov 26, 2022

@awawa-dev
Author

So 2.x caused that breaking change? Still it doesn't resolve the issue.
It's better for 900 byte frame but still experience degraded performance and very high error rate:
obraz

For comparison 1.0.6 could handle even 1800 byte frames:

obraz

SuGlider

SuGlider commented on Nov 26, 2022

@SuGlider
Collaborator

For 900, the solution is to replace Stream::readBytes() with HardwareSerial::read()

  uint16_t internalIndex = min(Serial.available(), MAX_BUFFER);
  if (internalIndex > 0)
  {
    lastDataTime = millis();
//    internalIndex = Serial.readBytes(buffer, internalIndex);
    internalIndex = Serial.read(buffer, internalIndex);
  }
  else if (lastDataTime + 1000 < millis())
  {
    Serial.println(framesReceived);
    lastDataTime = millis();
    framesReceived = 0;
    state = TestProtocol::HEADER_A;
  }
SuGlider

SuGlider commented on Nov 26, 2022

@SuGlider
Collaborator

Anyway, it doesn't work well with 1800. Let me analyze it further.

awawa-dev

awawa-dev commented on Nov 26, 2022

@awawa-dev
Author

Thank you for your time and effort. I can confirm that it works for 1200 bytes frames now with usually no errors. Then it gets worse quickly if the frame is only slightly bigger.

SuGlider

SuGlider commented on Nov 27, 2022

@SuGlider
Collaborator

@awawa-dev
PR #7525 allows the sketch presented in this issue to run perfectly fine with no errors.
I tested it with 5000 as packet size.

awawa-dev

awawa-dev commented on Nov 27, 2022

@awawa-dev
Author

Great! I will test it right away.

awawa-dev

awawa-dev commented on Nov 27, 2022

@awawa-dev
Author

@SuGlider Great job 😄 I've tested your PR not only using test sketch but also my main project: I confirm everything works now perfectly. Hope this PR will be merged soon. And that along with the changes you recommended here will finally allow me to upgrade my ESP32 LED driver to Arduino ESP32 ver. 2. Because of that performance issue, it was on hold for almost a year (I'm aware that it could be difficult to detect due specific serial chip capability and large frame/speed transmission configuration)

SuGlider

SuGlider commented on Nov 27, 2022

@SuGlider
Collaborator

Excellent!

14 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Possible regression of serial communication performance since version 2.x · Issue #7505 · espressif/arduino-esp32