Tasks 中的数组在 ESP32 中出现 Guru 错误

Array in Tasks make a Guru error with ESP32

提问人:nottaK was 提问时间:7/27/2023 最后编辑:gre_gornottaK was 更新时间:8/15/2023 访问量:41

问:

所以,我为这个 esp32 编写了一个程序。它有一些任务,一个给我带来了一些麻烦。它向我发送了一个 Guru 错误。这里是代码: 主 .cpp:

#include <Arduino.h>
#include <Document.h>

void updateDocument(void * par){ //Task to Update a document or create if not existing
  for(;;){
    Documentgetting();
    Documentupdate(); 
  }
}


void getLuxTempHum(void * par){ //Task to get Humidity Temperatur and Lux
  for(;;){
    gHumidity();
    gLux();
    gTemperatur();
  }
}


void getgps(void * par){ // Task to get GPS
  for(;;){
    gGPS();
  }
}

void setaktor(void * par){ // Task to get Aktoren
  for(;;){
    gmotor();
    /*LEDsss(dark);
    shakeit(shake);*/
  }
}

void getWindRain(void* arg){//Task for wind
  for(;;){
    gWind();
  }
}

void getMittelwert(void* par){//get Mittelwert from sensors
  for(;;){
    gMittelwerte();
  }

}


void setup()
{
  //****************************** TMP117 MS8607 TSL2591*********************************

      if(!tmp117.begin()){}
      configureSensor();
      if(!tsl.begin()){}
      if(!ms8607.begin()){}
      ms8607.setHumidityResolution(MS8607_HUMIDITY_RESOLUTION_OSR_8b);

         xTaskCreate(
            getLuxTempHum,
            "get LuxTempHum",
            10000, //make higher if complex task, 4500 mostlikely is enough for most jobs
            NULL,
            1,
            NULL
  );
  //***********************************************************************

    //***************************** Wind/Regen ************************************
    setupwr();

                 xTaskCreate(
            getWindRain,
            "getWindRain",
            4500, //make higher if complex task, 4500 mostlikely is enough for most jobs
            NULL,
            tskIDLE_PRIORITY,
            NULL
  );
  //*************************************************************************/

  //***************************** GPS****************************************
    setupGPS();
                 xTaskCreate(
            getgps,
            "get GPS",
            7000, //make higher if complex task, 4500 mostlikely is enough for most jobs
            NULL,
            1,
            NULL
  );
  //*************************************************************************/

  //******************************Aktoren************************************
    setupledandmotor();
                 xTaskCreate(
            setaktor,
            "set Aktor",
            4500, //make higher if complex task, 4500 mostlikely is enough for most jobs
            NULL,
            1,
            NULL
  );
  //*************************************************************************
    //****************************Mittelwert*********************************
    mittelsetup();
                 xTaskCreate(
            getMittelwert,
            "get Mittelwert",
            10000, //make higher if complex task, 4500 mostlikely is enough for most jobs
            NULL,
            1,
            NULL
  );
  //*************************************************************************/
  //**************************** Firebase *******************************
  setupFire();

     xTaskCreate(
    updateDocument,
    "update/create Document",
    20000, //make higher if complex task, 4500 mostlikely is enough for most jobs
    NULL,
    1,
    NULL
  );

    //*********************************************************************
}


void loop()
{
  if(gotwindgeschwingkeit>=11){
    Sperre=true;
    U=true;
    O=false;
    
  }else{
    Sperre=false;
  }
  delay(10);
   
}

任务 Mittelwert 给我带来了问题: Mittelwert.h:

#include <Arduino.h>
//******************************Lux, Temp, Hum*************************
#include <Lux.h>
#include <Temp.h>
#include <Humidity.h>
//********************************Wind/Regen***********************************
#include <WindRegen.h>

bool gethalfhour = false;
bool getthreeminutes = false;

int halfhouri = 0;
int threemini = 0;

double sensors[]={gotHum, gotLux, gotTemp, gotwindgeschwingkeit};
double sensorshh[sizeof(sensors)];
double sensorstm[sizeof(sensors)];

void mittelsetup(){
    for(int i = sizeof(sensors)-1; i>=0; i--){
        sensorshh[i]=sensors[i];
        sensorstm[i]=sensors[i];
    }
}

void updatesenorssss(){
    sensors[0]=gotHum;
    sensors[1]=gotLux;
    sensors[2]=gotTemp;
    sensors[3]=gotwindgeschwingkeit;

}




void gMittelwerte(){
    updatesenorssss();
    vTaskDelay(1000/portTICK_PERIOD_MS);

        halfhouri++;
        threemini++;
        

        for(int i = sizeof(sensors)-1; i>=0; i--){
            sensorshh[i]+=sensors[i];
            sensorstm[i]+=sensors[i];
        }

        if(gethalfhour){
            for(int i = sizeof(sensors)-1; i>=0; i--){
                sensorshh[i]=sensorshh[i]/halfhouri;
            }
            halfhouri=0;
            vTaskDelay(500/portTICK_PERIOD_MS);
            for(int i = sizeof(sensorshh)-1; i>=0; i--){
                sensorshh[i]=0;
            }
        }
        if(getthreeminutes){
            for(int i = sizeof(sensors)-1; i>=0; i--){
                sensorstm[i]=sensorstm[i]/threemini;
            }
            threemini=0;
            vTaskDelay(500/portTICK_PERIOD_MS);
            for(int i = sizeof(sensorstm)-1; i>=0; i--){
                sensorstm[i]=0;
            }
        }
    
    
}

如果我不启动任务,它就可以了。所以我不知道发生了什么,我试图找到错误,但正如你所看到的,我是一个初学者。

这里是错误代码:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x4016407f  PS      : 0x00060030  A0      : 0x80164165  A1      : 0x3ffb4e70  
A2      : 0x00000000  A3      : 0x3ffb4ebe  A4      : 0x00000001  A5      : 0x00000000
A6      : 0x00000000  A7      : 0x00000000  A8      : 0x80083c3c  A9      : 0x3ffb4e60
A10     : 0x3ff000e0  A11     : 0x00000001  A12     : 0x3ffbddc8  A13     : 0x00000000  
A14     : 0x007bf1f8  A15     : 0x003fffff  SAR     : 0x0000001d  EXCCAUSE: 0x0000001c
EXCVADDR: 0x0000000c  LBEG    : 0x40089dcc  LEND    : 0x40089de2  LCOUNT  : 0xffffffff  


Backtrace:0x4016407c:0x3ffb4e700x40164162:0x3ffb4e90 0x400e3695:0x3ffb4eb0 0x400e385f:0x3ffb4ee0 0x400d35d5:0x3ffb4f00 0x400d35f7:0x3ffb4f20 0x400d365a:0x3ffb4f40 

谢谢你的帮助!! 而且,我是奥地利人,所以我的英语不是最好的。

我也试图推荐一些零件,发现问题所在,并留下了 Mittelwert.h。我无法找出它的具体问题。所以,如果有人发现问题,请告诉我。第一个错误是看门狗错误,女巫我用Idle_Priority保护了,但后来是 Guru 错误。

C++ 错误处理 ESP32

评论


答:

0赞 Matias B 8/15/2023 #1

问题在于将运算符与数组一起使用的方式。sizeofsensors

sensors是一个包含 4 个双精度值的数组,假设每个双精度值需要 8 个字节的内存,那么将返回 8x4=32,而不是您期望的 4。因此,在 for 循环中,您尝试访问数组中超出您定义的 4 个元素限制的位置,从而导致您得到的错误。sizeof(sensors)LoadProhibited

要获取数组的实际长度,您应该使用 。sizeof(sensors) / sizeof(sensors[0])

double sensors[] = {1, 2, 3, 4};
printf("sizeof(sensors) = %ld\n", sizeof(sensors)); // Output: sizeof(sensors) = 32
printf("Array length = %ld\n", sizeof(sensors) / sizeof(sensors[0])); // Output: Array length = 4