Skip to content

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

Closed
@KurtE

Description

@KurtE

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.

Activity

mjs513

mjs513 commented on Jan 18, 2025

@mjs513

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @KurtE@mjs513@facchinm

      Issue actions

        GIGA: Serial.flush() will hang if the Serial monitor is not connected. · Issue #35 · arduino/ArduinoCore-zephyr