arduino / arduino/ArduinoCore-mbed
GIGA R1 - SerialX.flush() does not work
- Dominant language
- C
- Stars
- 411
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
As I mentioned in the forum post:
[SerialX (X=1-4) are unbuffered? surprised ](https://forum.arduino.cc/t/serialx-x-1-4-are-unbuffered-surprised/1178363?u=kurte)
The call to SerialX.flush() does not work as I expected, nor does it comply with the documentation.
https://www.arduino.cc/reference/en/language/functions/communication/serial/flush/
>Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this instead removed any buffered incoming serial data.)
To reproduce:
```
void setup() {
Serial1.begin(115200);
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
Serial1.print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
Serial1.flush();
digitalWrite(2, LOW);
delay(1);
digitalWrite(2, HIGH);
for (char ch = 'a'; ch <= 'z'; ch++) Serial1.write(ch);
Serial1.flush();
digitalWrite(2, LOW);
delay(1000);
}
```
Results captured by Logic analyzer:

The hardware appears to have a Transfer Complete (TC) status, which looks like it should be able to do this properly.
Alternatively, is to add some random delay after your transfers to make up for this issue, which I personally would prefer to avoid.
Otherwise, you are likely to see variations of this same issue, like: #389
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the provided sketch on a GIGA R1 and inspect the SerialX.flush() implementation and the hardware's Transfer Complete status. Compare the observed logic-analyzer timing with the documented flush behavior; done means flush waits until outgoing serial transmission has completed without requiring an added delay.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, c
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100