Skip to content

Serial.flush() blocks forever #597

@jpmeijers

Description

@jpmeijers

Using the latest version of the SAMD core, doing a Serial.flush() will hang forever.

Problem can be reproduced using this sketch:

void setup() {
  SerialUSB.begin(115200);
  delay(2000);
  SerialUSB.println("Start");

  Serial.begin(9600);
  Serial.flush();

  SerialUSB.println("Setup end");
}

void loop() {
  SerialUSB.println("Loop");
  delay(1000);
}

Which will only print:

15:19:30.572 -> Start

Tracing the issue down takes me to Serial.flush(), which is defined in Uart.cpp. This calls sercom->flushUART(); in SERCOM.cpp.

The previous versions of this core had the following code:

void SERCOM::flushUART()
{
  // Skip checking transmission completion if data register is empty
  if(isDataRegisterEmptyUART())
    return;

  // Wait for transmission to complete
  while(!sercom->USART.INTFLAG.bit.TXC);
}

The current version has the if(isDataRegisterEmptyUART()) commented out:

// if(isDataRegisterEmptyUART())
// return;

I don't understand why this is commented out, as clearly the while(!sercom->USART.INTFLAG.bit.TXC); will never return if flush() is called when the TX buffer is already empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy