Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wdt reset at use pinMode+analogWrite #4688

Closed
bstsoftorg opened this issue Apr 27, 2018 · 11 comments
Closed

wdt reset at use pinMode+analogWrite #4688

bstsoftorg opened this issue Apr 27, 2018 · 11 comments
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.

Comments

@bstsoftorg
Copy link

bstsoftorg commented Apr 27, 2018

Basic Infos

Platform

  • Hardware: ESP-12
  • Core Version: 2,4,1
  • Development Env: Arduino IDE
  • Operating System: Windows

Settings in IDE

  • Module: Generic ESP8266 Module
  • Flash Mode: qio
  • Flash Size: 4MB/3MB
  • lwip Variant: v2 Higher Bandwidth
  • Reset Method: ck
  • Flash Frequency: 80Mhz
  • CPU Frequency: 80Mhz
  • Upload Using: SERIAL
  • Upload Speed: 115200

Problem Description

I tried to switch to 2.4.1 and found a strange reboot. There are no such problems with version 2.3.0-rc2.
If in 2.4.1 to perform before pinMode analogWrite no matter what speed, this is a "wdt reset". This problem is manifested when you call to pinMode+analogWrite times per second and the day of these reboots was to 20. But it's tests when using 1 port, if the ports will be greater, the stability at all. Also, tests have shown that very frequent falls occur during rapid circulation. See log.

MCVE Sketch

/* 
  FSWebServer - Example WebServer with SPIFFS backend for esp8266
  Copyright (c) 2015 Hristo Gochkov. All rights reserved.
  This file is part of the ESP8266WebServer library for Arduino environment.
 
  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.
  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  
  upload the contents of the data folder with MkSPIFFS Tool ("ESP8266 Sketch Data Upload" in Tools menu in Arduino IDE)
  or you can upload the contents of a folder if you CD in that folder and run the following command:
  for file in `ls -A1`; do curl -F "file=@$PWD/$file" esp8266fs.local/edit; done
  
  access the sample web page at http://esp8266fs.local
  edit the page by going to http://esp8266fs.local/edit
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <FS.h>

#define DBG_OUTPUT_PORT Serial

//const char* ssid = "wifi-ssid";
//const char* password = "12345678";//wifi-password";
const char* ssid = "d1";
const char* password = "f#stin@t25";/**/
const char* host = "esp8266fs";

ESP8266WebServer server(80);
//holds the current upload
File fsUploadFile;

//format bytes
String formatBytes(size_t bytes){
  if (bytes < 1024){
    return String(bytes)+"B";
  } else if(bytes < (1024 * 1024)){
    return String(bytes/1024.0)+"KB";
  } else if(bytes < (1024 * 1024 * 1024)){
    return String(bytes/1024.0/1024.0)+"MB";
  } else {
    return String(bytes/1024.0/1024.0/1024.0)+"GB";
  }
}

String getContentType(String filename){
  if(server.hasArg("download")) return "application/octet-stream";
  else if(filename.endsWith(".htm")) return "text/html";
  else if(filename.endsWith(".html")) return "text/html";
  else if(filename.endsWith(".css")) return "text/css";
  else if(filename.endsWith(".js")) return "application/javascript";
  else if(filename.endsWith(".png")) return "image/png";
  else if(filename.endsWith(".gif")) return "image/gif";
  else if(filename.endsWith(".jpg")) return "image/jpeg";
  else if(filename.endsWith(".ico")) return "image/x-icon";
  else if(filename.endsWith(".xml")) return "text/xml";
  else if(filename.endsWith(".pdf")) return "application/x-pdf";
  else if(filename.endsWith(".zip")) return "application/x-zip";
  else if(filename.endsWith(".gz")) return "application/x-gzip";
  return "text/plain";
}

bool handleFileRead(String path){
  DBG_OUTPUT_PORT.println("handleFileRead: " + path);
  if(path.endsWith("/")) path += "index.htm";
  String contentType = getContentType(path);
  String pathWithGz = path + ".gz";
  if(SPIFFS.exists(pathWithGz) || SPIFFS.exists(path)){
    if(SPIFFS.exists(pathWithGz))
      path += ".gz";
    File file = SPIFFS.open(path, "r");
    size_t sent = server.streamFile(file, contentType);
    file.close();
    return true;
  }
  return false;
}

void handleFileUpload(){
  if(server.uri() != "/edit") return;
  HTTPUpload& upload = server.upload();
  if(upload.status == UPLOAD_FILE_START){
    String filename = upload.filename;
    if(!filename.startsWith("/")) filename = "/"+filename;
    DBG_OUTPUT_PORT.print("handleFileUpload Name: "); DBG_OUTPUT_PORT.println(filename);
    fsUploadFile = SPIFFS.open(filename, "w");
    filename = String();
  } else if(upload.status == UPLOAD_FILE_WRITE){
    //DBG_OUTPUT_PORT.print("handleFileUpload Data: "); DBG_OUTPUT_PORT.println(upload.currentSize);
    if(fsUploadFile)
      fsUploadFile.write(upload.buf, upload.currentSize);
  } else if(upload.status == UPLOAD_FILE_END){
    if(fsUploadFile)
      fsUploadFile.close();
    DBG_OUTPUT_PORT.print("handleFileUpload Size: "); DBG_OUTPUT_PORT.println(upload.totalSize);
  }
}

void handleFileDelete(){
  if(server.args() == 0) return server.send(500, "text/plain", "BAD ARGS");
  String path = server.arg(0);
  DBG_OUTPUT_PORT.println("handleFileDelete: " + path);
  if(path == "/")
    return server.send(500, "text/plain", "BAD PATH");
  if(!SPIFFS.exists(path))
    return server.send(404, "text/plain", "FileNotFound");
  SPIFFS.remove(path);
  server.send(200, "text/plain", "");
  path = String();
}

void handleFileCreate(){
  if(server.args() == 0)
    return server.send(500, "text/plain", "BAD ARGS");
  String path = server.arg(0);
  DBG_OUTPUT_PORT.println("handleFileCreate: " + path);
  if(path == "/")
    return server.send(500, "text/plain", "BAD PATH");
  if(SPIFFS.exists(path))
    return server.send(500, "text/plain", "FILE EXISTS");
  File file = SPIFFS.open(path, "w");
  if(file)
    file.close();
  else
    return server.send(500, "text/plain", "CREATE FAILED");
  server.send(200, "text/plain", "");
  path = String();
}

void handleFileList() {
  if(!server.hasArg("dir")) {server.send(500, "text/plain", "BAD ARGS"); return;}
  
  String path = server.arg("dir");
  DBG_OUTPUT_PORT.println("handleFileList: " + path);
  Dir dir = SPIFFS.openDir(path);
  path = String();

  String output = "[";
  while(dir.next()){
    File entry = dir.openFile("r");
    if (output != "[") output += ',';
    bool isDir = false;
    output += "{\"type\":\"";
    output += (isDir)?"dir":"file";
    output += "\",\"name\":\"";
    output += String(entry.name()).substring(1);
    output += "\"}";
    entry.close();
  }
  
  output += "]";
  server.send(200, "text/json", output);
}

void setup(void){
  DBG_OUTPUT_PORT.begin(115200);
  DBG_OUTPUT_PORT.print("\n");
  DBG_OUTPUT_PORT.setDebugOutput(true);
  SPIFFS.begin();
  {
    Dir dir = SPIFFS.openDir("/");
    while (dir.next()) {    
      String fileName = dir.fileName();
      size_t fileSize = dir.fileSize();
      DBG_OUTPUT_PORT.printf("FS File: %s, size: %s\n", fileName.c_str(), formatBytes(fileSize).c_str());
    }
    DBG_OUTPUT_PORT.printf("\n");
  }
  

  //WIFI INIT
  DBG_OUTPUT_PORT.printf("Connecting to %s\n", ssid);
  if (String(WiFi.SSID()) != String(ssid)) {
    WiFi.begin(ssid, password);
  }
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    DBG_OUTPUT_PORT.print(".");
  }
  DBG_OUTPUT_PORT.println("");
  DBG_OUTPUT_PORT.print("Connected! IP address: ");
  DBG_OUTPUT_PORT.println(WiFi.localIP());

  MDNS.begin(host);
  DBG_OUTPUT_PORT.print("Open http://");
  DBG_OUTPUT_PORT.print(host);
  DBG_OUTPUT_PORT.println(".local/edit to see the file browser");
  
  
  //SERVER INIT
  //list directory
  server.on("/list", HTTP_GET, handleFileList);
  //load editor
  server.on("/edit", HTTP_GET, [](){
    if(!handleFileRead("/edit.htm")) server.send(404, "text/plain", "FileNotFound");
  });
  //create file
  server.on("/edit", HTTP_PUT, handleFileCreate);
  //delete file
  server.on("/edit", HTTP_DELETE, handleFileDelete);
  //first callback is called after the request has ended with all parsed arguments
  //second callback handles file uploads at that location
  server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload);

  //called when the url is not defined here
  //use it to load content from SPIFFS
  server.onNotFound([](){
    if(!handleFileRead(server.uri()))
      server.send(404, "text/plain", "FileNotFound");
  });

  //get heap status, analog input value and all GPIO statuses in one json call
  server.on("/all", HTTP_GET, [](){
    String json = "{";
    json += "\"heap\":"+String(ESP.getFreeHeap());
    json += ", \"analog\":"+String(analogRead(A0));
    json += ", \"gpio\":"+String((uint32_t)(((GPI | GPO) & 0xFFFF) | ((GP16I & 0x01) << 16)));
    json += "}";
    server.send(200, "text/json", json);
    json = String();
  });
  server.begin();
  DBG_OUTPUT_PORT.println("HTTP server started");

}
 
/*void loop(void){
  server.handleClient();
}*/

uint32 qqq = 0;

void loop() {
  server.handleClient();
Serial.print(F("*1*="));
Serial.print(qqq);
//if (qqq == 0)
    pinMode(13, OUTPUT);
    analogWrite(13, qqq);
Serial.println(F("*3*"));
qqq++;
}

Debug Messages


 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

*1*=8293*3*
*1*=8294
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

*1*=3173*3*
*1*=3174*3*
*1*=3175
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

*1*=8292*3*
*1*=8293*3*
*1*=8294
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

*1*=17601*3*
*1*=17602*3*
*1*=17603
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

*1*=8292*3*
*1*=8293*3*
*1*=8294
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld

*1*=11457*3*
*1*=11458*3*
*1*=11459
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v614f7c32
~ld


@devyte
Copy link
Collaborator

devyte commented Apr 28, 2018

@bstsoftorg please edit your issue and fix the sketch. The C in MCVE is for Complete.

@devyte devyte added the waiting for feedback Waiting on additional info. If it's not received, the issue may be closed. label Apr 28, 2018
@bstsoftorg
Copy link
Author

Everything is standard FS Browser and replace a single procedure. Here's the updated sketch for you, only to sense no the same error:
`
1=21533
1=21543
1=2155
ets Jan 8 2013,rst cause:4, boot mode:(1,7)

wdt reset
`

@msilenius
Copy link

analogwrite is currently bugged, cf issue 4321

#4321 the workaround described there is working

@bstsoftorg
Copy link
Author

`
...
void setup(void){
...
pinMode(15, OUTPUT);
analogWrite(15, 0);
analogWrite(15, 10);
}

/void loop(void){
server.handleClient();
}
/

uint32 qqq = 0;

void loop() {
server.handleClient();
Serial.print(F("1="));
Serial.print(qqq);
//if (qqq == 0)
pinMode(15, OUTPUT);
analogWrite(15, qqq);
Serial.println(F("3"));
qqq++;
}
result
1=114573
1=114583
1=11459
ets Jan 8 2013,rst cause:4, boot mode:(1,6)

wdt reset
`

This is not a workaround since all ports are used by the system and are not free.
16 the port is generally the port is connected through a resistor 471 with Rosatom.
At any time, any of the ports 0, 12, 13, 14, 15 can have values from 0 to 1023
Free ports simply aren't present.
Also, at any time, the port can become digital or analog. The system is non-static and fully dynamic depending on the situation.
Such problems there is no in 2.3.0rc2, so you need to see what changes were made after this version in PWM functions.

@msilenius
Copy link

msilenius commented May 10, 2018

you misunderstand the workaround. Choose a GPIO port that you don't use anywhere in your scketch and put in the setup:

pinMode(your pin you don't use, OUTPUT);
analogWrite(your pin you don't use, 0);
analogWrite(your pin you don't use, 10);

then never use that port in you sketch (15 should be perfect for that)

@bstsoftorg
Copy link
Author

bstsoftorg commented May 10, 2018

I understood described idea but all ports from 0 PL 17 are occupied!!!
You need to was so and write that code not the existing port.

  pinMode(255, OUTPUT);
  analogWrite(255, 0);
  analogWrite(255, 10);
}
 
/*void loop(void){
  server.handleClient();
}*/

uint32 qqq = 0;

void loop() {
  server.handleClient();
Serial.print(F("*1*="));
Serial.print(qqq);
//if (qqq == 0)
    pinMode(15, OUTPUT);
    analogWrite(15, qqq);
Serial.println(F("*3*"));
qqq++;
}

@devyte
Copy link
Collaborator

devyte commented Nov 14, 2018

@bstsoftorg there have been several fixes merged since this was reported. Is this still valid in 2.4.2? In latest git (aka latest master branch)?

@devyte
Copy link
Collaborator

devyte commented Dec 5, 2018

Closing due to lack of feedback and age.

@devyte devyte closed this as completed Dec 5, 2018
@ateeb327
Copy link

Hello, I was getting the same wdt reset error while trying to use pinMode with digitalWrite() function.
I solved it by figuring out how the Wemos Pin mapping works.
Actually, you need to refer the pin in 'Dx' notation.
e.g digitalWrite(D15,LOW);
or
pinMode(D15, OUTPUT);

Also, make sure to select "Wemos D1 R1" in Tools > Boards so that Dx constants will match
the labels.

@HejaSverige
Copy link

@ateeb327:
Thank you man, you really made my day. :-) I was close to madness because of that problem. I'm using the NodeMCU 1.0 (ESP-12E) and as soon as I used the pinMode command, the wdt reset error occured. Now everything works fine, so thank you once again.

@slellis
Copy link

slellis commented Mar 31, 2020

Hi all,

I faced this problem recently.
For future reference, what happened to me was an error in the definition of the board.
I am using a Nodemcu and had set ESP8266 generic 1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for feedback Waiting on additional info. If it's not received, the issue may be closed.
Projects
None yet
Development

No branches or pull requests

6 participants