Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrupted UART data with large buffers - work around found. #710

Open
reubenstr opened this issue Aug 4, 2023 · 1 comment
Open

Corrupted UART data with large buffers - work around found. #710

reubenstr opened this issue Aug 4, 2023 · 1 comment

Comments

@reubenstr
Copy link

reubenstr commented Aug 4, 2023

When receiving image buffers over UART on a Teensy 4.1 at 916200 BAUD from an ESP32-Cam nearly all images become corrupted. Corrupted images contain a valid first portion of 1/4 to 3/4 of the image with the remaining portion being the previous image.

The UART uses the addMemoryForRead() method to add 100k PSRAM to the RX buffer and typical image size is 25k.
Images are sent to the Teensy on demand and between image request the clear() method is called to ensure a empty UART RX buffer.

The below workaround allows for uncorrupted images:
Inside the clear() method in the file HardwareSerial.cpp...
Remove:
rx_buffer_head_ = rx_buffer_tail_;
Add:

rx_buffer_head_ = 0;
rx_buffer_tail_ = 0;

Nothing obvious sticks out when looking at the read() method concerning the ring buffer.

@PaulStoffregen
Copy link
Owner

I'm concerned this could create a race condition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants