Esp32-C3 Bootlooping

Hi, I am making a project using the esp32-c3. I have run into a strange problem. My code started to boot loop and in order to make it accept connections again I had to remove all components. After I did that I started to try and see what the problem is. I have narrowed it down, but it is very strange. This is my loop():

void loop() {
  server.handleClient();
  delay(1000);

  looped();
}

It works fine like this, but add anything in the loop. Doesn't matter what it is, Variable declaration, Serial print, etc. It just starts bootlooping and I have no idea why in the world this takes place. Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).

The rest of the main file

#include <WiFi.h>
#include <Preferences.h>
#include <WebServer.h>
#include "esp32/rtc.h"
#include <FastLED.h>

#include "utils.h"

int count = 0;
bool Joanne = true;

WebServer server(80);
Preferences data;

HTTPClient http;

CRGB led[1];

bool wasNear = false;
int offtime = -1;

bool isNear() {if (digitalRead(D6) == HIGH){return true;}else{return false;}}
bool isCharging() {if (digitalRead(D0) == HIGH){return true;}else{return false;}}
bool wasCharging = false;

bool connectWifi() {
  Serial.println("Checkpoint9");
    String ssid = data.getString("ssid", "");
    String password = data.getString("pass", "");

    if (ssid.length() == 0 || password.length() == 0) {
        return false;
    }

    Serial.println("Verbinden met netwerk...");
    WiFi.begin(ssid.c_str(), password.c_str());

    int timeout = 10; // 10 seconden timeout om verbinding te maken
    while (WiFi.status() != WL_CONNECTED && timeout > 0) {
        delay(1000);
        timeout--;
    }
  Serial.println("Checkpoint10");
    Serial.println("Verbonden?");
    return isWiFiActive();
}

// Functie om AP-modus te starten
void startAPMode() {
    WiFi.softAP("Snuffel", "123456789");
    Serial.println("Access Point Started!");
    server.on("/", handleData);
    server.begin();
}

void stopAPMode() {
    WiFi.softAPdisconnect(true);
    server.stop();
}

bool isWiFiActive() {
    return WiFi.status() == WL_CONNECTED;
}

void handleData() {
  data.putString("ssid", server.arg("ssid"));
  data.putString("pass", server.arg("pass"));
  String testValue = server.arg("test");

  if (testValue == "true") {
    server.send(200, "text/plain", "SnuffelWuppieValidated");
  } else {
    if (connectWifi()) {
        server.send(200, "text/plain", "Wifi Connected");
    } else {
        server.send(200, "text/plain", "Wifi Failed");
    }
  }
}

void getData() {
  if (downloadData("NewData", Joanne).toInt() == 1) {
    data.putString("Lkleur", downloadData("Lkleur", Joanne));
    data.putString("Kkleur", downloadData("Kkleur", Joanne));
    data.putInt("SlaapTijd", downloadData("SlaapTijd", Joanne).toInt());
    data.putInt("OntwaakTijd", downloadData("OntwaakTijd", Joanne).toInt());
    data.putInt("SlaapDuratie", downloadData("SlaapDuratie", Joanne).toInt());
    uploadData("NewData", 0);
  }
}

void looped() {
  if (count == 10) {
    if (!isWiFiActive()) {
        connectWifi();
    }
    if (isCharging) {
        getData();
    }
    if (downloadData("Slapen", !Joanne).toInt() == 1) {
        setLed(data.getString("Lkleur"));
    } else {
        setLed(data.getString("Kkleur"));
    }
    count = 0;
  }
  count++;
}

void setup() {
  Serial.begin(9600);

  data.begin("Snuffel", false); // Open data
  FastLED.addLeds<WS2812B, D10, GRB>(led, 1);

  led[0] = CRGB(0, 0, 0);
  FastLED.show();

  pinMode(D6, INPUT);
  pinMode(D0, INPUT);

  http.begin("my url");
  http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  if (!connectWifi()) {
    startAPMode();
  }

  setupRTC();
}

void loop() {
  server.handleClient();
  delay(1000);

  looped();

}

Well, can't say for sure, not all the code is here..
But from what I see, your loop is not looping..
The watchdog does not get reset..
Going to have to feed the dog yourself occasionally..

esp_task_wdt_reset();

good luck.. ~q

looks like a watchdog timeout where you are spending too much time in an operation (typically a loop) and not clearing the WDT
put in Serial.println() commands to show the flow of control and values of key variables

Found the problem. In the Looping() function I tried calling isCharging(), but I forgot the (). Don't know why the ide didn't spit out an compile error :man_shrugging:. Anyway, thanks for the suggestions!

Actually not found the problem. It is still bootlooping, but. When I flash new firmware and upload the sketch it works. When I then restart the esp it starts bootlooping again...

Which Arduino core implementation do you use?

I think so. The OP is advised to look into net and find the codes for reset_wdt/similar command for ESP32 and insert it at the suitable place of the loop() function.

Are you using any GPIO pins which have special purposes, for example ESP32 SPI flash memory? It is not clear from the information supplied which pins are in use for your application.
See: ESP32 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

Bootlooping stopped again. I added an delay in the setup function and it is working again. Lets hope it wont find it's way back :crossed_fingers:

Well, it's a timing thing, so yeah maybe you get lucky for a spell..
but you really need to pat the dog..
there's a looptask behind the scenes..
https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/main.cpp

  for (;;) {
#if CONFIG_FREERTOS_UNICORE
    yieldIfNecessary();
#endif
    if (loopTaskWDTEnabled) {
      esp_task_wdt_reset();
    }
    loop();
    if (serialEventRun) {
      serialEventRun();
    }
  }

that's the forever for loop that runs your loop, you can see each time before the loop is executed, this is called..

esp_task_wdt_reset();

If your loop takes too long to reset the watch dog, you reboot..
probably need to add the above function inside your looped() routine..
can't hurt but should help..

good luck.. ~q

It never actually reached the loop. With the delay in the void setup() it works. I have added some code in the loop and setup and it works. If it starts looping again I will for sure look at adding your code.

you're are correct..
looking closer at your error message..
it's not the idle task, it's an interrupt watchdog..
and i don't see you using interrupts..
could be something with FastLED??
think this means interrupts were stopped for too long..
hoping it stays away..

~q

Probably is, removing the FastLed line worked. I updated but still the same. The delay is no problem for me so I am fine now :upside_down_face: