首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >古鲁冥想错误: ESP32上的核心1恐慌(禁止加载)

古鲁冥想错误: ESP32上的核心1恐慌(禁止加载)
EN

Stack Overflow用户
提问于 2021-08-04 19:34:55
回答 1查看 2.7K关注 0票数 2

因此,我试图创建一个网络服务器,用一个ESP32点亮多个LED。当按下按钮时,服务器将发送一个GET请求。这是以前的工作,只有一个LED和一个按钮的HTML页面。这段代码就是,只要有更多的按钮和变量。但是,当我将它上传到ESP32并打开串行窗口时,我得到如下信息:

rst:0xc (SW_CPU_RESET),引导: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模式:DIO,clock div:1 load:0x3fff 0018,len:4 load:0x3fff001c,len:1216 ho 0尾12房间4加载:0x40078000,len:10944 load:0x40080400,len:6388条目0x400806b4 Guru Meditation错误:核心1‘恐慌(LoadProhibited)。异常没有得到处理。核心1寄存器转储: PC : 0x40081041 PS : 0x00060330 A0 : 0x800d1222 A1 : 0x3ffb1f40 A2 : 0x00000004 A3 : 0x00000002 A4 : 0x0800001c A5 : 0x00000003 A6 : 0x00000003 A7 : 0x00000000 A8 : 0x3f401e08 A9 :0x00000000 A10 : 0xff4e0000 A11 : 0x00000048 A12 : 0x08000000 A13 : 0x00000003 A14 : 0xffffffff A15 : 0x00000000 SAR : 0x0000001a EXCCAUSE: 0x0000001c EXCVADDR: 0xff4e0000 LBEG : 0x00000000贷款: 0x00000000 LCOUNT : 0x00000000 精灵文件SHA256: 0000000000000000回溯: 0x40081041:0x3ffb1f40 0x400d121f:0x3ffb1f60 0x400dc8f6:0x3ffb1fb00x40089a52:0x3ffb1fd0重新启动

我不知道这意味着什么或者我做错了什么。我试过:

1-最小化变量(在变量的前缀中添加无符号、const等)

2-将变量放入局部函数的作用域

有人能帮忙吗?如果你愿意的话,我会非常感激的。(我对Arduino编程完全陌生,所以我不知道该怎么做)。下面是代码:

代码语言:javascript
复制
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoOTA.h>

// Replace with your network credentials
const char* ssid = "SSID_HERE";
const char* password = "PASSWORD_HERE";


const unsigned int outputfw = 2;
const unsigned int outputlt = 4;
const unsigned int outputrt = 7;
const unsigned int outputbw = 6;

// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <title>ESP Web Server</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    html {font-family: Arial; display: inline-block; text-align: center;}
    h2 {font-size: 3.0rem;}
    p {font-size: 3.0rem;}
    body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}
    .switch {position: relative; display: inline-block; width: 120px; height: 68px} 
    .switch input {display: none}
    .slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; border-radius: 34px}
    .slider:before {position: absolute; content: ""; height: 52px; width: 52px; left: 8px; bottom: 8px; background-color: #fff; -webkit-transition: .4s; transition: .4s; border-radius: 68px}
    input:checked+.slider {background-color: #2196F3}
    input:checked+.slider:before {-webkit-transform: translateX(52px); -ms-transform: translateX(52px); transform: translateX(52px)}
  </style>
</head>
<body>
  <h2>ESP Web Server</h2>
  %BUTTONPLACEHOLDER%
<script>function toggleCheckbox(state, dir) {
  console.log("Mouse is ")
  console.log(state)
  var xhr = new XMLHttpRequest();
  if(state){ xhr.open("GET", "/update?" + dir + "=" + state, true); }
  else { xhr.open("GET", "/update?" + dir + "=" + state, true); }
  xhr.send();
}

document.getElementById("fw").addEventListener("mousedown", function(event) {
    toggleCheckbox(true, "fw");
    console.log("mouse down.f");
}, false);
document.getElementById("fw").addEventListener("mouseup", function(event) {
    toggleCheckbox(false, "fw");
    console.log("mouse up.f")
}, false);
document.getElementById("bw").addEventListener("mousedown", function(event) {
    toggleCheckbox(true, "bw");
    console.log("mouse down.b");
}, false);
document.getElementById("bw").addEventListener("mouseup", function(event) {
    toggleCheckbox(false, "bw");
    console.log("mouse up.b")
}, false);
document.getElementById("lt").addEventListener("mousedown", function(event) {
    toggleCheckbox(true, "lt");
    console.log("mouse down.l");
}, false);
document.getElementById("lt").addEventListener("mouseup", function(event) {
    toggleCheckbox(false, "lt");
    console.log("mouse up.l")
}, false);
document.getElementById("rt").addEventListener("mousedown", function(event) {
    toggleCheckbox(true, "rt");
    console.log("mouse down.r");
}, false);
document.getElementById("rt").addEventListener("mouseup", function(event) {
    toggleCheckbox(false, "rt");
    console.log("mouse up.r")
}, false);

</script>
</body>
</html>
)rawliteral";

// Replaces placeholder with button section in your web page
String processor(const String& var){
  //Serial.println(var);
  if(var == "BUTTONPLACEHOLDER"){
    String buttons;
    String outputStateValue = outputState();
    //buttons+= "<h4>Output - GPIO 2 - State <span id=\"outputState\"></span></h4><label class=\"switch\"><input type=\"checkbox\" onchange=\"toggleCheckbox(this)\" id=\"output\" " + outputStateValue + "><span class=\"slider\"></span></label>";
    buttons = "<h4>output button gpio5 - <span id=\"outputState\"></span></h4><button id=\"fw\">forward</button><br><button id=\"lt\">left</button><button id=\"bw\">backward</button><button id=\"rt\">right</button>";
    return buttons;
  }
  return String();
}

String outputState(){
  if(digitalRead(outputfw)){
    return "checked";
  }
  else {
    return "";
  }
  return "";
}

void setup(){
  // Serial port for debugging purposes
  Serial.begin(115200);
  
  pinMode(outputfw, OUTPUT);
  pinMode(outputbw, OUTPUT);
  pinMode(outputlt, OUTPUT);
  pinMode(outputrt, OUTPUT);
  digitalWrite(outputfw, LOW);
  digitalWrite(outputbw, LOW);
  digitalWrite(outputlt, LOW);
  digitalWrite(outputrt, LOW);
//  pinMode(buttonPin, INPUT);
  
  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi..");
  }

  // Print ESP Local IP Address
  Serial.println(WiFi.localIP());
  ArduinoOTA.begin();

  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html, processor);
  });

  // Send a GET request to <ESP_IP>/update?<direction>=<inputMessage>
  server.on("/update", HTTP_GET, [] (AsyncWebServerRequest *request) {
    int ledState1 = LOW;          // the current state of the output pin
  int ledState2 = LOW;
  int ledState3 = LOW;
  int ledState4 = LOW;
    String inputMessage;
    String inputParam;
    const char PARAM_INPUT_1[] = "fw";
const char PARAM_INPUT_2[] = "bw";
const char PARAM_INPUT_3[] = "lt";
const char PARAM_INPUT_4[] = "rt";

    // GET input1 value on <ESP_IP>/update?state=<inputMessage>
    if (request->hasParam(PARAM_INPUT_1)) {
      inputMessage = request->getParam(PARAM_INPUT_1)->value();
      inputParam = PARAM_INPUT_1;
      digitalWrite(outputfw, inputMessage.toInt());
      ledState1 = !ledState1;
    }
    else if (request->hasParam(PARAM_INPUT_2)) {
      inputMessage = request->getParam(PARAM_INPUT_2)->value();
      inputParam = PARAM_INPUT_2;
      digitalWrite(outputbw, inputMessage.toInt());
      ledState2 = !ledState2;
    }
    else if (request->hasParam(PARAM_INPUT_3)) {
      inputMessage = request->getParam(PARAM_INPUT_3)->value();
      inputParam = PARAM_INPUT_3;
      digitalWrite(outputlt, inputMessage.toInt());
      ledState3 = !ledState3;
    }
    if (request->hasParam(PARAM_INPUT_4)) {
      inputMessage = request->getParam(PARAM_INPUT_4)->value();
      inputParam = PARAM_INPUT_4;
      digitalWrite(outputrt, inputMessage.toInt());
      ledState4 = !ledState4;
    }
    else {
      inputMessage = "No message sent";
      inputParam = "none";
    }
    Serial.println(inputMessage);
    request->send(200, "text/plain", "OK");
  });

  // Send a GET request to <ESP_IP>/state
  server.on("/state", HTTP_GET, [] (AsyncWebServerRequest *request) {
    request->send(200, "text/plain", String(digitalRead(outputfw)).c_str());
  });
  // Start server
  server.begin();
}
  
void loop() {
  ArduinoOTA.handle();
  delay(2);}
EN

回答 1

Stack Overflow用户

发布于 2021-08-15 01:00:28

你使用的是GPIO引脚连接到ESP32 32的闪存芯片。当你用pinMode()重新编程的时候,你会干扰ESP32 32读写闪存的能力,它就会崩溃。

代码语言:javascript
复制
const unsigned int outputfw = 2;
const unsigned int outputlt = 4;
const unsigned int outputrt = 7;
const unsigned int outputbw = 6;

引脚6和7连接到SPI闪存芯片。它们在应用程序中通常是不安全的。它们通常也不表达在ESP32的突破板上。

试着用13和14这样的安全引脚来重建固件,而不是6和7,你会发现它不会像它那样崩溃。

也许你把突破板的密码和GPIO的密码搞混了?为了找到正确的GPIO引脚,你需要参考板的插脚。ESP32 Arduino代码指的是GPIO引脚号,而不是插板引脚号。

对于如何使用ESP32 GPIO引脚以及哪些引脚是安全的,这里有一个非常有用的参考。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68657106

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档