3 bytes via SerialUSB freezes Arduino Due after Serial Monitor close on Win10

Hi,

I have discovered an unexpected behavior of Arduino Due + Windows 10, running the following sketch:

unsigned long currentTime = 0;
unsigned long LEDSwitchTime = 0;
byte LEDState = 0;

void setup() {pinMode(13, OUTPUT);}

void loop() {
 currentTime = millis();
 if (currentTime - LEDSwitchTime > 1000) {
   digitalWrite(13, LEDState); 
   if (LEDState) {
       SerialUSB.print('A');
   }
   LEDState = 1-LEDState;
   LEDSwitchTime = currentTime;
 }
}

As per the sketch, Arduino Due flashes its onboard LED and sends character 'A' via the native USB port once per second.
Initially when plugged into Win7 or Win10 machines, it blinks endlessly.
If on Win10 (but not on Win7) you open the Arduino serial monitor to view the 'A's, and then close the serial monitor, it will blink 3 more times and then freeze the main loop (i.e. no more blinking). If you re-open the serial monitor, the main loop resumes and the three A's arrive at the terminal.

This freezing behavior seems to be specific to Arduino Due and Windows 10. I tested the following configurations and none freeze after closing the serial monitor:

  • Win7+Due
  • Win10+M0
  • Win10+Teensy3.6

I tried to make transmission conditional on the port being open with:

if (SerialUSB) {
  SerialUSB.print('A');
}

but no dice.

Does anyone have insight into why the Due main loop is freezing with Win10, and how to avoid it?

Thanks!!