cores icon indicating copy to clipboard operation
cores copied to clipboard

Corrupted UART data with large buffers - work around found.

Open reubenstr opened this issue 1 year ago • 1 comments

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.

reubenstr avatar Aug 04 '23 17:08 reubenstr

I'm concerned this could create a race condition

PaulStoffregen avatar Sep 08 '24 13:09 PaulStoffregen