PlatformIO serial monitor crashes NodeMCU ESP32s

Hello, I’m starting out with PlatformIO and ESP32 and I am trying to get the arduino simple wifi server sketch to work.:

#include <Arduino.h>
#include <WiFi.h>

const char* ssid     = "Rajat's WiFi";
const char* password = "*********";

WiFiServer server(80);


void setup() {
    Serial.begin(115200);
    pinMode(LED_BUILTIN, OUTPUT);      // set the LED pin mode

    delay(10);

    // We start by connecting to a WiFi network

    Serial.println();
    Serial.println();
    Serial.print("Connecting to ");
    Serial.println(ssid);

    WiFi.begin(ssid, password);

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected.");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
    
    server.begin();
}

int value = 0;

void loop () {
  WiFiClient client = server.available();
  if (client) {                             // if you get a client,
    Serial.println("New Client.");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"/H\">here</a> to turn the LED on pin 5 on.<br>");
            client.print("Click <a href=\"/L\">here</a> to turn the LED on pin 5 off.<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /H")) {
          digitalWrite(LED_BUILTIN, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(LED_BUILTIN, LOW);                // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    Serial.println("Client Disconnected.");
  }
}

It compiles and uploads fine, but as soon as I open the PlatformIO serial monitor, I get the error Guru Meditation Error: Core panic'ed (Interrupt wdt timeout on CPU0) and the MCU stops working. Note that the regular arduino serial monitor never shows this problem.
I need the serial monitor for the time being for debugging purposes, I would be grateful if someone points me out the problem.
My platformio.ini:

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200

The sketch you’ve linked to is for a board having a WiFi shield. Not an ESP32. Are you sure you don’t want to run HelloServer.ino?

I’m sorry. I thought that’s the default wifi sketch that comes with the Arduino IDE because it looked same. I’ll update with the whole code.
Anyway, I just noticed that if I put the ESP32 on a breadboard instead of holding in my hand/leaving it on my table with floating pins, the problem goes away. What’s bugging me is that the Arduino’s serial monitor just works, no matter what. Why does PlatformIO’s serial monitor cause my MCU to crash?

That would be beyond weird if that was the case. If you flashed the (wrong) firmware via PlatformIO and observe the serial monitor in PlatformIO, it should give the same result as in the Arduino IDE serial monitor, if the firmware is not re-uploaded in the Arduino IDE. The firmware should be the cause of the crash, not the serial monitor.

Hmm… spooky stuff.

  1. I compile and upload the program using platform io, it does that successfully
  2. I press the reset button, it works, connects to the router, and I can find a corresponding ip in my router. I can see the webpage it serves at the ip. Everything works as expected.
  3. I open the platform io serial monitor to check the outputs, and it immediately crashes the MCU. I won’t be able to find the ip anymore.
  4. I close the platform io serial monitor, open Arduino ide, open serial monitor, reset the MCU, it works as expected and Arduino ide serial monitor displays everything as expected.
  5. I close Arduino ide, open platform io’s serial monitor, it crashes immediately.
    etc…

Meanwhile I’m using the MCU being plugged into a breadboard, but as is well known I think, ESP32 dev boards fit awkwardly in a breadboard, but that seems to solve the problem. Maybe it’s because of loose connections and a poorly developed error checking/unsafe serial buffer implementation of the serial terminal in PlatformIO?
Only thing I can tell is that it is reproducible with 3 different ESP32 dev boards I have, so it’s not particular to the one I used initially.

Is the crash reproducable when you press the reset button on the board again?

Yes. If I keep PlatformIO’s serial monitor open then when resetting, it crashes at a random point. Sometimes right at the beginning, most of the times during WiFi.begin(ssid, password);, and sometimes in the loop(). But it does crash, sooner or later.

Can you add

build_type = debug
monitor_filters = esp32_exception_decoder

to the platformio.ini to get a better crash log, and post that?

Also what version of the Arduino ESP32 core do you have installed in the Arduino IDE? The very latest 2.0 version?

It’s so weird… As I said, I was using the ESP32 board plugged into a breadboard and it was working fine with PlatformIO’s serial monitor and as soon as I took it out and tried uploading/running it again, the crashes are back. Anyway, here’s what you asked:

Connecting to Rajat's WiFi
....p��ՁMeditation Error: Core� 0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at ��0089958: 190c020c 209329���
�17420
Core 0 registe��"յ��
PC      : 0x400899��c  PS      : 0x00060433  A��     : 0x8008587e  A1    ����ffb5700
A2      :���0000000  A3      : 0x0�������
�      : 0x00060���
�      : 0x00000001  �����      : ��0060820  �����`000000  A8      : 0x00000000  A9      : 0x00000001  
A10     : 0x00060420  A11     : 0x00060823  A12     : 0x00060820  A13     : 0x3ffb5768
A14     : 0x00000019  A15     : 0x001fb475  SAR     : 0x00000018  EXCCAUSE: 0x00000000  
EXCVADDR: 0x00000000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff

ELF file SHA256: 0000000000000000

Backtrace: 0x4008995c:0x3ffb5700 0x4008587b:0x3ffb5720 0x40083f9f:0x3ffb5740 0x40102a40:0x3ffb5760 0x40089832:0x3ffb5790
  #0  0x4008995c:0x3ffb5700 in xPortInIsrContext at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)
  #1  0x4008587b:0x3ffb5720 in wifi_bt_common_module_enable at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/driver/periph_ctrl.c:263
  #2  0x40083f9f:0x3ffb5740 in esp_phy_common_clock_enable at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/phy_init.c:524
  #3  0x40102a40:0x3ffb5760 in ppTask at ??:?
  #4  0x40089832:0x3ffb5790 in vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c:355 (discriminator 1)

Rebooting...
ets Jun  8 2016 00:22:57

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:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8


Connecting to Rajat's WiFi
....Guru Meditation Error: Core  panic'ed (Interrupt wdt timeout on CPU0)
Core 0 register dump:
PC       0x40086c2  PS       0x00060434  A0       0x80102aa A1       0x3fb730
A2       0x00000000  A3       0xffff  A4       0x00000001  A5       0x3f73c4  
A6       0x3f74270  A7       0x3fb1f  A8       0x400f240  A9       0x3f08414
A10      0x00000000  A11      0x0000007f A12      0x3f73c4  A13      0x00000001  
A14      0x3fcb4  A15      0x00000000  SAR      0x00000020  EXCCAUSE 0x00000005
EXCVADDR 0x00000000  LBEG     0x4000ce  LEND     0x4000cf  LCOUNT   0xffff  

ELF file SHA256: 000000000000000

Backtrace:0x40086c2:0x3fb7300x40102a7:0x3fb760 0x40089832:0x3fb790
  #0  0x40086c2:0x3fb7300 in ?? ??:0

ore 1 register dump:
PC       0x401429b  PS       0x00060c4  A0       0x80131056  A1       0x3fb680
A2       0x00000000  A3       0x80000001  A4       0x00000000  A5       0x00000001
A6       0x00060c0  A7       0x00000000  A8       0x00060023  A9       0x3fb77c
A10      0x00000001  A11      0x00000001  A12      0x80089a4  A13      0x3fb580
A14      0x00000000  A15      0x3fb380  SAR      0x00000000  EXCCAUSE 0x00000005  
EXCVADDR 0x00000000  LBEG     0x00000000  LEND     0x00000000  LCOUNT   0x00000000

ELF file SHA256: 000000000000000

Backtrace:0x401429b:0x3fb6800x40131053:0x3fb6a 0x4008ae:0x3fb6c 0x40089832:0x3fb6e
  #0  0x401429b:0x3fb6800 in ?? ??:0

Rebooting...

In the Arduino boards manager, it says Esp32 2.0.0-alpha 1.

Hm… I’ve never seen that type of backtrace before where it crashes in… xPortInIsrContext.

PlatformIO in its latest release uses 1.0.6. Does it behave like that in the Arduino IDE when you install that version? (You can always switch back)

I tried to change versions, it downloaded and installed, v1.0.6 onwards disappeared from version selection, but it still shows v2.0.0-alpha 1. And the program doesn’t crash. I can’t remove and add it again it either. It shows some java null pointer exception if I try to remove it. :frowning_face:

o_o that’s not good. In extreme cases try to restart the Arduino IDE are reinstall it. The core is always re-installable and you can backup existing libraries in C:\Users\<user>\Documents\Arduino\libraries.

Though I don’t have any idea why the program is behaving eratically in the first place. Sounds like a hardware issue if it works inside a breadboard but not outside… But then again why would it work in the Arduino IDE and not PlatformIO.

Yeah. I’ll try reinstalling and update on this later. Meanwhile I should mention platform io’s flashing feels weird too. I don’t have to hold the programming button on MCU board, it right away starts flashing. With Arduino ide, it waits till I hold the programming button down for a while. And all of these problems are reproducible on all 3 boards I have. I just got them yesterday.

Nope I checked. No problem with v1.0.6 in Arduino IDE. And PlatformIO’s serial monitor keeps crashing my MCU randomly with the typical output:

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
flash read err, 1000
ets_main.c 371
ets Jun  8 2016 00:22:57

rst:0x10 (RTCWDT_RTC_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:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8


Connecting to Rajat's WiFi
....Guru Meditation Error: Core  panic'ed (Interrupt wdt timeout on CPU0)
Core 0 register dump:
PC       0x40086c2  PS       0x00060434  A0       0x801017d  A1       0x3fb6e
A2       0x00000a8  A3       0x000000a  A4       0x10892018  A5       0x3fcf4  
A6       0x00000000  A7       0x3fb138  A8       0x00000001  A9       0x3fc174
A10      0x00000000  A11      0x00000000  A12      0x00000000  A13      0x00000001  
A14      0x00060420  A15      0x00000000  SAR      0x00000019  EXCCAUSE 0x00000005
EXCVADDR 0x00000000  LBEG     0x4000ce  LEND     0x4000cf  LCOUNT   0xffff  

ELF file SHA256: 000000000000000

Backtrace:0x40086c2:0x3fb6e 0x401017d:0x3fb760 0x400897f:0x3fb790
  #0  0x40086c2:0x3fb6e in ?? ??:0
  #1  0x401017d:0x3fb760 in ?? ??:0
  #2  0x400897f:0x3fb790 in ?? ??:0

ore 1 register dump:
PC       0x401411d  PS       0x00060e4  A0       0x8012f32  A1       0x3fb680
A2       0x00000000  A3       0x00000001  A4       0x80089ac A5       0x3fb5a
A6       0x00000000  A7       0x3fb380  A8       0x00000020  A9       0x80000020
A10      0x00000008  A11      0x00000001  A12      0x00000005  A13      0x00000020
A14      0x00000020  A15      0x10000000  SAR      0x00000000  EXCCAUSE 0x00000005
EXCVADDR 0x00000000  LBEG     0x00000000  LEND     0x00000000  LCOUNT   0x00000000

ELF file SHA256: 000000000000000

Backtrace:0x401411d:0x3fb6800x4012f2f0x3fb6a 0x4008aa:0x3fb6c 0x400897f:0x3fb6e
  #0  0x401411d:0x3fb6800 in ?? ??:0

Rebooting...

I hope someone sheds some light into this.

Ive done a number of ESP32 projects all using Platform IO. Can you post your project platformio.ini file?

I already put it in the question as I thought it’s important too. It’s just

[env:nodemcu-32s]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200

PlatformIO in its latest release uses 1.0.6.

This became a problem to me today. ESP32’s bluetooth master mode/discovery mode doesn’t seem to work with old versions. I’m talking about this example. I feel bad for having to leave a real IDE in favor of arduino IDE :frowning_face:

If you really-really want to use this 2.0.0-alpha version, you can follow ESP32-Arduino - platformio support for 2.0.0 version - #2 by maxgerhardt to use it.

When I take the above code as src\main.cpp, add a #include <Arduino.h> in front of it and use with a platformio.ini of

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
platform_packages =
   toolchain-xtensa32 @ ~2.80400.0
   framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.0-alpha1
monitor_speed = 115200

I get a successfull build

Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]   7.2% (used 23436 bytes from 327680 bytes)
Flash: [=======   ]  69.7% (used 913716 bytes from 1310720 bytes)
Building .pio\build\esp32dev\firmware.bin
esptool.py v3.0
============ [SUCCESS] Took 16.79 seconds ============

and if I upload & monitor

rst:0x10 (RTCWDT_RTC_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:0x3fff0030,len:1252
load:0x40078000,len:12692
load:0x40080400,len:3100
entry 0x400805ec
The device started, now you can pair it with bluetooth!
Starting discoverAsync...Findings will be reported in "btAdvertisedDeviceFound"
Found a device asynchronously: Name: Redmi max, Address: b4:c4:fc:42:xx:xx, cod: 58987, rssi: -61
Stopping discoverAsync... stopped
Starting discover...
>> Dump scan results: 1
- 1: Name: Redmi max, Address: b4:c4:fc:42:xx:xx, cod: 58987, rssi: -55
-- Dump finished --
1 Like

OOF BIG THANKS. After a little bit of tinkering(installing git, I already had git in visual studio but it didn’t work outside VS, and updating esptoolpy, letting intellisense rebuild indexes for quite some time) it finally compiles!
Thanks a bunch!!

I always use the following in my platformio.ini file for all my ESP32 projects

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200