Serial Monitor is disconnecting after ESP.restart(). It did not do that

Hello !

I’ve made a restart method for my project. Basically, it counts down from 5 to 0 and then does a ESP.restart().

//------------------------- restart_sequence()
void restart_sequence(unsigned int countdown) {
  for(int i = countdown; i>=0; i--) {
    matrix->clear();
    matrix->setFont(NULL);
    matrix->setTextSize(1);
    matrix->setTextColor(LED_RED_HIGH);
    matrix->setCursor(1,1);
    matrix->print("Restarting");
    matrix->setCursor(20,15);
    matrix->print((String)"in " + i);
    matrix->show();
    delay(1000);
  }
  server.reset();
  delay(900);
  matrix->clear();
  delay(100);
  ESP.restart();
}

I have a flag in void loop() that checks if I issued a restart or not.

void loop() {
  if (restartFlag) {
    restart_sequence(5);
  }
// ...
}

All worked dandy and fine, until I’ve added enableCore1WDT(); to void setup()

void setup() {
  Serial.begin(115200);
  delay(1000);
  enableCore1WDT()
// ...
}

Now, after every restart, the following exception is being thrown:

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6412
entry 0x400806a8

--- exit ---
Exception in thread rx:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/george/.platformio/penv/local/lib/python2.7/site-packages/serial/tools/miniterm.py", line 445, in reader
    data = self.serial.read(self.serial.in_waiting or 1)
  File "/home/george/.platformio/penv/local/lib/python2.7/site-packages/serial/serialposix.py", line 501, in read
    'device reports readiness to read but returned no data '
SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

And then the Serial Monitor disconnects.
I have no idea why that happens.

Any advice ?

What happens if you init Serial AFTER enableCore1WDT() instead of before it? It could be exactly what the error says… i.e. device reports readiness to read but returned no data