arduino/ArduinoCore-zephyr

GIGA: Serial.flush() will hang if the Serial monitor is not connected.

KurtE opened this issue · 1 comments

Describe the bug
Title pretty well describes it.
Optional: attach the sketch

Additional context
Running current stuff in the arduino branch, after the recent merge.

void setup() {
  Serial.begin(115200);
  while(!Serial && (millis() < 4000)) {}
  Serial.println("Quick and dirty test");
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(LED_BUILTIN+1, OUTPUT);
  pinMode(LED_BUILTIN+2, OUTPUT);
}

int loop_count = 0;
void loop() {
  Serial.print("Loop count: ");
  Serial.println(++loop_count);
  Serial.flush();
  digitalWrite(LED_BUILTIN, (loop_count & 1)? HIGH : LOW);
  digitalWrite(LED_BUILTIN+1, (loop_count & 2)? HIGH : LOW);
  digitalWrite(LED_BUILTIN+2, (loop_count & 4)? HIGH : LOW);
  delay(250);
}

If you run the sketch above, without the Serial monitor connected, it will hang at the flush. It will startup when
you connect and it will stop again if you should close it.

If you comment out the Serial.flush(), it runs without this issue.

@KurtE
Gave your sketch a try and am seeing the same as think as you are with Serial.flush().