Skip to content

Conversation

@facchinm
Copy link
Member

  • The aynchronous nature of the DRE and TXC interrupt flags
    causes issues (lockups) when the TX DATA register is empty on start
    and a flush is issued. Simply looking at the DRE prior to
    waiting for TXC is insufficient because the data register
    may well be empty but the shift register could still contain
    data, in this case SERCOM::flushUART() would return before TXC
    has been raised thus before flushing is complete.
  • bool added to SERCOM.h to indicate when it is ok for
    SERCOM::flushUART() to wait for the TXC flag. This flag is
    set when any data is written to the data register via
    SERCOM::writeDataUART(). It is cleared when a flush is done.

Fixes #597

* The aynchronous nature of the DRE and TXC interrupt flags
  causes issues (lockups) when the TX DATA register is empty on start
  and a flush is issued. Simply looking at the DRE prior to
  waiting for TXC is insufficient because the data register
  may well be empty but the shift register could still contain
  data, in this case SERCOM::flushUART() would return before TXC
  has been raised thus before flushing is complete.
* bool added to SERCOM.h to indicate when it is ok for
  SERCOM::flushUART() to wait for the TXC flag. This flag is
  set when any data is written to the data register via
  SERCOM::writeDataUART(). It is cleared when a flush is done.
@ArduinoBot
Copy link

✅ Build completed.

⬇️ Build URL: http://downloads.arduino.cc/PR/samd/package_samd-b216_index.json

ℹ️ To test this build:

  1. Open the Preferences of the Arduino IDE.
  2. Add the Build URL above in the Additional Boards Manager URLs field, and click OK.
  3. Open the Boards Manager (menu Tools->Board->Board Manager...)
  4. Install Arduino SAMD core - Pull Request fix Serial.flush() blocks forever #597 #652
  5. Select one of the boards under SAMD Pull Request fix Serial.flush() blocks forever #597 #652 in Tools->Board menu
  6. Compile/Upload as usual

@facchinm facchinm merged commit a5d52db into arduino:master Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serial.flush() blocks forever

2 participants