esp8266 / Arduino

ESP8266 core for Arduino
GNU Lesser General Public License v2.1
15.98k stars 13.33k forks source link

ESP-12E troubleshooting (rst cause:2, boot mode:(3,6)) #2414

Closed rkoptev closed 8 years ago

rkoptev commented 8 years ago

Basic Infos

Hardware

Hardware: ESP-12E (ESP8266MOD) Core Version: 2.3.0

Description

Hi. Previously, I was able to flash ESP through Arduino IDE. The code worked well, although very often controller restarted with no reason. "... wdt reset ..." has been written to the COM port. I tried to turn off the watch dog timer with the help of ESP.wdtDisable() or simply to increase the timeout with ESP.wdtEnable(65535). This partly solves the problem, but restarts still have a place to be. But now, after a regular flashing I get this output in COM port:

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v09f0c112 ~ld

And that's all. I tried to change the module in the IDE to "ESP8266 Generic", and to change the size of the memory, but no result. What could be the problem? And how to fix this behavior?

Settings in IDE

Module: NodeMCU 1.0 Flash Size: 4MB/3MB CPU Frequency: 80Mhz Upload Using: SERIAL

Sketch


#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>
#include <FS.h>

#define DEV true

#define STEPPER_EN_PIN   13
#define STEPPER_DIR_PIN  2
#define STEPPER_STEP_PIN 5

#define STEPPER_RPM 600
#define STEPPER_GEAR_RATIO 64
#define STEPPER_MICROSTEP 16
#define STEPPER_FULL_ROTATION 7000

#define SERVER_URL "example.com"
#define SERVER_PORT 80
#define SERVER_CONNECTION_INTERVAL 10000

#define WIFI_DATA_FILENAME "/wifi.txt"
#define WIFI_CONNECTION_TIMEOUT 10000

ESP8266WebServer server(80);

char* ssid = new char[32];
char* password = new char[64];

bool jalousieState;

void moveStepper(unsigned long steps, bool direction) {
  unsigned long period = 60000000L / (STEPPER_RPM * STEPPER_GEAR_RATIO * STEPPER_MICROSTEP * 2UL);
  steps *= STEPPER_GEAR_RATIO;
  Serial.print("Period = ");
  Serial.println(period);
  digitalWrite(STEPPER_DIR_PIN, direction);
  digitalWrite(STEPPER_EN_PIN, LOW);
  for (int i = 0; i < steps; i++) {
    digitalWrite(STEPPER_STEP_PIN, HIGH);
    delayMicroseconds(period);
    digitalWrite(STEPPER_STEP_PIN, LOW);
    delayMicroseconds(period);
    ESP.wdtFeed();
  }
  digitalWrite(STEPPER_EN_PIN, HIGH);
}

void jalousieClose() {
  if (!jalousieState)
    return;
  Serial.println("Closing jalousie");
  moveStepper(STEPPER_FULL_ROTATION, 1);
  jalousieState = false;
}

void jalousieOpen() {
  if (jalousieState)
    return;
  Serial.println("Opening jalousie");
  moveStepper(STEPPER_FULL_ROTATION, 0);
  jalousieState = true;
}

void jalousieHome() {
  moveStepper(STEPPER_FULL_ROTATION, 1);
  jalousieState = false;
}

void handleWiFiCredentials() {
  if (!server.hasArg("SSID") || !server.hasArg("password")) { server.send(500, "text/plain", "Bag arguments"); return; }

  Serial.print("WiFi Credentials:\nSSID: ");
  Serial.println(server.arg("SSID"));
  Serial.print("Password: ");
  Serial.println(server.arg("password"));

  File wifiData = SPIFFS.open(WIFI_DATA_FILENAME, "w");
  wifiData.println(server.arg("SSID"));
  wifiData.println(server.arg("password"));
  wifiData.close();

  server.send(200, "text/plain", "Data saved");
  ESP.reset();
}

bool loadWiFiCredentials() {
  File wifiData = SPIFFS.open(WIFI_DATA_FILENAME, "r");
  if (!wifiData)
    return false;

  String _ssid = wifiData.readStringUntil('\n');
  _ssid.trim();
  _ssid.toCharArray(ssid, 32);

  String _password = wifiData.readStringUntil('\n');
  _password.trim();
  _password.toCharArray(password, 64);

  wifiData.close();
  return true;
}

void setup() {
  // Make the watch dog timeout longer
  ESP.wdtEnable(65535);

  Serial.begin(74880);
  Serial.setDebugOutput(DEV);

  pinMode(STEPPER_EN_PIN, OUTPUT);
  pinMode(STEPPER_DIR_PIN, OUTPUT);
  pinMode(STEPPER_STEP_PIN, OUTPUT);
  digitalWrite(STEPPER_EN_PIN, HIGH);

  // Initialize filesystem
  SPIFFS.begin();

  bool loaded = loadWiFiCredentials();
  if (loaded) {
    Serial.println("WiFi credentials loaded");
    unsigned long connectionTime = millis();
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
      delay(100);
      if (millis() - connectionTime > WIFI_CONNECTION_TIMEOUT) {
        Serial.println("Connection failed. Ereasing old Wifi credentials and starting AP to get new credentials.");
        SPIFFS.remove(WIFI_DATA_FILENAME);
        ESP.reset();
      }
    }
  } else {
    Serial.println("WiFi credentials not found, starting AP");

    WiFi.mode(WIFI_AP);
    WiFi.softAP("Pentagon228");

    server.serveStatic("/", SPIFFS, "/public_html/WifiSetup.html");
    server.serveStatic("/WifiSetup.css", SPIFFS, "/public_html/WifiSetup.css");
    server.serveStatic("/WifiSetup.js", SPIFFS, "/public_html/WifiSetup.jsl");
    server.on("/submit", HTTP_POST, handleWiFiCredentials);

    server.begin();

    while(1) {
      server.handleClient();
      ESP.wdtFeed();
    }
  }
  jalousieHome();
}

void loop() {
  delay(SERVER_CONNECTION_INTERVAL);
  Serial.println("I'm alive");

  WiFiClient client;
  if (!client.connect(SERVER_URL, SERVER_PORT))
    return;

  client.print(String("GET / HTTP/1.1\r\n") +
                      "Host:" + SERVER_URL + ":" + SERVER_PORT + "\r\n" + 
                      "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    ESP.wdtFeed();
    delay(100);
    if (millis() - timeout > 5000) {
      client.stop();
      return;
    }
  }

  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.println("Res: " + line);
    line.trim();
    if (line.equals(String("open"))) {
      jalousieOpen();
      return;
    } else if (line.equals(String("close"))) {
      jalousieClose();
      return;
    }
  }
}
muito93 commented 4 years ago

Hi, I have solved the problem by Tools > Erase Flash > All contents compiled and uploaded again the boot problem did not occur anymore ... until now !

@hassin23ayz It worked, thank you

shubham-kulkarni commented 4 years ago

I am facing the same issue. I accidentally pressed "reset" button on the board while uploading was in progress (nearly 60%). Now when I am connecting the board to my PC, its detected. I am also able to upload the sketch to the board. But its misbehaving. Inbuilt LED is constantly flashing and I see the mentioned error on serial screen (Baud Rate 115200 / NL&CR).

vivekanandRdhakane commented 4 years ago

Hi, I have solved the problem by Tools > Erase Flash > All contents compiled and uploaded again the boot problem did not occur anymore ... until now !

thanks. It worked

faelpinho commented 4 years ago

Have no solution? I got only this message when GPIO_0 is GND: " ets Jan 8 2013,rst cause:2, boot mode:(3,6)

ets_main.c "

Nothing more. And I got this message when GPIO_0 is VCC: " ets Jan 8 2013,rst cause:2, boot mode:(1,7)" Nothing more.

I have clicked "Erase" button on ESP8266 Download Tool V.3.6.8, and the prompt shows this message: CONNECT BAUD: 115200

.Uploading stub... Running stub... Stub running...

crc_efuse_4bit: 0 crc_calc_4bit: 8 48bit mac "

Sem título

bbxmbb commented 4 years ago

I solve this problem when download older version of the esp8266 to version 2.5.0 and everything works again.

skybadger commented 4 years ago

I am using ESP8266-12 and 2.6.3 core. I had this problem and walked back to code, sorted out some bad variables ( clash with internal libraries vs local include settings, turned off pre-cache to ensure libraries got rebuilt and fixed my pins allocation - I was forgetting pins are not the same as GPIOs and it all works.

Oh, and having downloaded the GH latest head ( v4.1) , I still needed to add the ICACHE RA ATTR in front of all the ISR functions. But it is working and with interrupts too. Very nice. Took about 3 hours of faff when it should have taken 5 mins but that's hardware.

k-byte-rgb commented 4 years ago

Find the problem, since I am new to esp8266, don't know bad program will cause rest loop of hardware ...., Download another program solve the problem ...

which programmer?

DavidDeeds commented 3 years ago

I had the same issue and resolved it. My code was originally written using ESP8266 Arduino Core 2.6.3 (or close to - it was an older version..). I updated to ESP8266 Arduino Core 2.7.4 tonight and got this issue.

I recalled reading in recent months that there were some changes and enhancements in how interrupts ( ISR s ) were handled as a result of the ESP8266 Arduino Core development over time.

I revisited my interrupt code and had to add ICACHE_RAM_ATTR in.

There is a good read here on stackoverflow about it: https://stackoverflow.com/questions/58113937/esp8266-arduino-why-is-it-necessary-to-add-the-icache-ram-attr-macro-to-isrs-an and also the general ESP8266 Arduino Core reference library here https://arduino-esp8266.readthedocs.io/en/latest/reference.html

My boards are both the Lolin Wemis D1 Mini Pro 2.0.0 and Lolin Wemis D1mini that I was experiencing this on. Problem solved and not soo much time lost! Hope this helps someone else!! :)

ThovReime commented 3 years ago

I had the same problem, solved it with hassin23ayz 's method: Tools -> Erase flash -> All flash contents. No more rst cause:2 boot mode (3,6), all working well :)

mmdhossein commented 3 years ago

The problem i had (rst cause:1, boot mode:(3,7)), was laid down in my code where i defined an ISR which encountered the code memory and due to that , esp rebooted continuously. Thanks to this thread, i used ICACHE_FLASH_ATTR in my ISR function which solved the rebooting thing. Hope it be a help for anyone have my problem.

jhalak333 commented 3 years ago

this is due to long processing on loop while acting as webserver...

k-byte-rgb commented 3 years ago

Fine problem solve a while ago thanks for the awnsers sorry for not responding

Outlook for Androidhttps://aka.ms/ghei36 downloaden


From: jhalak333 @.> Sent: Saturday, March 27, 2021 9:54:20 AM To: esp8266/Arduino @.> Cc: k-byte-rgb @.>; Comment @.> Subject: Re: [esp8266/Arduino] ESP-12E troubleshooting (rst cause:2, boot mode:(3,6)) (#2414)

this is due to long processing on loop while acting as webserver...

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/esp8266/Arduino/issues/2414#issuecomment-808694585, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQLDSIJ37L2VUXKZYB5MSILTFWMLZANCNFSM4CNEQWYQ.

Archy404 commented 3 years ago

To everyone having the same Problem as the OP. I had it too.

The Problem is, that the ESP8266 crashes during the rotation of the stepper motor because it can not handle the WiFi tasks that continuisly run in the background while only having a few microseconds delay.

I added the yield(); function to my rotation loops and the crashes are gone.

At least that was the Problem with me, since we are basically doing the same thing and i had the problem i assume this would be the solution for this case too.

AbdelrahmanMryan commented 3 years ago

Try to upload a blink code on Arduino Uno , then switch to ESP and upload the code again , I had the same problem and it solved

HamzaHajeir commented 3 years ago

Hi, I have solved the problem by Tools > Erase Flash > All contents compiled and uploaded again the boot problem did not occur anymore ... until now !

It seems to work

But it's too ugly to be forced to do it everytime, especially if we must do dynamic configuration each time! Why just does it happens?

jorgecujcuj commented 2 years ago

me dio ese error:

ets Jan 8 2013,rst cause:2, boot mode:(3,6) load 0x4010f000, len 3460, room 16 tail 4 chksum 0xcc load 0x3fff20b8, len 40, room 4 tail 4 chksum 0xc9 csum 0xc9 v00041c40 ~ld

lo que hice fue eliminar la librería de LiquidCrystal_I2C y funciono de nuevo con otra librería

whogarden commented 2 years ago

If it can help. I had the same pb (from initial post 20 Aug 2016) Just try Flash mode : "Dout compatible" DOUT

halilcankaroglu commented 2 years ago

I have same issue. ESP8266 in restarting loop. I try this ICACHE_RAM_ATTR and working :) you must add before setup() and same name your method like this void ICACHE_RAM_ATTR door();

I had the same issue and resolved it. My code was originally written using ESP8266 Arduino Core 2.6.3 (or close to - it was an older version..). I updated to ESP8266 Arduino Core 2.7.4 tonight and got this issue.

I recalled reading in recent months that there were some changes and enhancements in how interrupts ( ISR s ) were handled as a result of the ESP8266 Arduino Core development over time.

I revisited my interrupt code and had to add ICACHE_RAM_ATTR in.

There is a good read here on stackoverflow about it: https://stackoverflow.com/questions/58113937/esp8266-arduino-why-is-it-necessary-to-add-the-icache-ram-attr-macro-to-isrs-an and also the general ESP8266 Arduino Core reference library here https://arduino-esp8266.readthedocs.io/en/latest/reference.html

My boards are both the Lolin Wemis D1 Mini Pro 2.0.0 and Lolin Wemis D1mini that I was experiencing this on. Problem solved and not soo much time lost! Hope this helps someone else!! :)

ttww commented 2 years ago

Hi folks,

I encountered the same issue with boot modes(1,6) and (3,6). Development went perfectly fine and all was running smooth at 2am. Revisiting the project the next morning all went to custard.

Finally I found the culprit and the cause for having the effect with the boot modes.

The exact reason for the continues boot mode errors shown I can;t give, but in my project it was some code failing in a class initialization of a global instance which runs before setup() is called. Took me a while to figure out, but I got there.

So my recommendation if you encounter the same issue: Look to your global class instances and see if code is causing exceptions before setup() is called!

Cheers, Klaus

Same problem here. I had some errors in a global class instance (SoftwareSerial) which cause this problem. The declaration for the baudRate were u_int8_t instead u_int_32 and switching to 19200 leads to an overflow which leads to a baud rate of 0 which leads to a division by zero exception....

Thank you Klaus!

Ciao Thomas

villivateur commented 1 year ago

Hi, I have solved the problem by Tools > Erase Flash > All contents compiled and uploaded again the boot problem did not occur anymore ... until now !

It works. But I just wonder, why?