Heap Corruption Guru Meditation Error: Core 1 panic'ed (StoreProhibited)

imranrajjad
Posts: 1
Joined: Fri Dec 11, 2020 9:30 am

Heap Corruption Guru Meditation Error: Core 1 panic'ed (StoreProhibited)

Postby imranrajjad » Fri Dec 11, 2020 10:47 am

Hello,

My ESP sketch scans for Bluetooth devices and shares data across Mesh. Recently I wanted to add an OLED display but this has resulted in Heap corruption. For Mesh I am using https://www.arduino.cc/reference/en/lib ... less-mesh/ Painless Mesh library, for OLED I am using https://github.com/ThingPulse/esp8266-oled-ssd1306 esp8266-oled-ssd1306 library.

I am getting the following error on Serail port and the ESP32 keeps on restarting. I am using ESP-AI Thinker board.

Code: Select all

Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.
Core 1 register dump:
PC      : 0x400923e2  PS      : 0x00060b33  A0      : 0x80094276  A1      : 0x3ffcfb50  
A2      : 0xef0a0000  A3      : 0x0000abab  A4      : 0xb33fffff  A5      : 0x00000001  
A6      : 0x00060920  A7      : 0x0000cdcd  A8      : 0x0000abab  A9      : 0x3ffcfc70  
A10     : 0x3ffc1790  A11     : 0x3f4019ff  A12     : 0x00000005  A13     : 0x3ffcfcb0  
A14     : 0x3ffcfc30  A15     : 0x00000008  SAR     : 0x00000020  EXCCAUSE: 0x0000001d  
EXCVADDR: 0xef0a0000  LBEG    : 0x4000c2e0  LEND    : 0x4000c2f6  LCOUNT  : 0xffffffff  

Backtrace: 0x400923e2:0x3ffcfb50 0x40094273:0x3ffcfb80 0x400948f7:0x3ffcfba0 0x40087ac0:0x3ffcfbc0 0x40087d63:0x3ffcfbe0 0x40087dcf:0x3ffcfc00 0x40146cad:0x3ffcfc50 0x40144cad:0x3ffcfc70 0x400e0c80:0x3ffcfca0 0x400d215d:0x3ffcfcd0 0x400d80a9:0x3ffcfd10 0x400e573b:0x3ffcfd40 0x400913d5:0x3ffcfd60

After decoding the error

Code: Select all

PC: 0x400923e2: vTaskEnterCritical at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/include/freertos/portmacro.h line 285
EXCVADDR: 0xef0a0000

Decoding stack results
0x400923e2: vTaskEnterCritical at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/include/freertos/portmacro.h line 285
0x40094273: multi_heap_internal_lock at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap.c line 375
0x400948f7: multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c line 190
0x40087ac0: heap_caps_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 111
0x40087d63: heap_caps_calloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 325
0x40087dcf: heap_caps_calloc_prefer at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c line 227
0x40146cad: future_new at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/bluedroid/osi/future.c line 29
0x40144cad: esp_bluedroid_init at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/bt/bluedroid/api/esp_bt_main.c line 136
0x400e0c80: BLEDevice::init(std::__cxx11::basic_string  , std::allocator  >) at C:\Users\imran\Documents\Arduino\libraries\ESP32_BLE_Arduino\src\BLEDevice.cpp line 379
0x400d215d: setup_ble() at C:\Users\imran\Documents\Arduino\sketch_dec09b/sketch_dec09b.ino line 172
0x400d80a9: setup() at C:\Users\imran\Documents\Arduino\sketch_dec09b/sketch_dec09b.ino line 127
0x400e573b: loopTask(void*) at C:\Users\imran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\cores\esp32\main.cpp line 14
0x400913d5: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143
As you can see the error occurs at line 172 where I am trying to write to a pointer location. Strangely commenting the OLED setup function makes the error goes away. Has anyone else come across similar problem?

Code: Select all

#include <Arduino.h>
#include "namedMesh.h"

#include <esp_log.h>

//this needs to be same
#define   MESH_SSID       "whateverYouLike"
#define   MESH_PASSWORD   "somethingSneaky"
#define   MESH_PORT       5555

//BLE
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>

//OLED
#include <Wire.h>  // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`

#define SDA 0
#define SCL 16
#define OLED_I2C_ADDR 0x3c

SSD1306Wire  display(OLED_I2C_ADDR, SDA, SCL);

void setup_ble();
void setup_mesh();
void setup_oled();
void drawLines();

Scheduler taskScheduler; // to control your personal task
namedMesh mesh;

String nodeName = "esp32_ble"; // Name needs to be unique

#define LED_BUILTIN 4
//LED BUILT_IN is GPIO 33 
//int LED_BUILT_IN = 33;
int scanTime = 5; //In seconds
BLEScan* pBLEScan; // THIS IS THE POINTER THAT IS GETTING CORRUPTED


Task taskBLEScanner( TASK_SECOND*30, TASK_FOREVER, []() {
  //scan_devices();  
  BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
  Serial.print("Devices found: ");
  Serial.println(foundDevices.getCount());
  Serial.println("Scan done!");
  pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory    
  digitalWrite(LED_BUILTIN, LOW); //Turn off
}); // start with a one second interval

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
      digitalWrite(LED_BUILTIN, HIGH); //Turn on    
    }
};

void setup() {
  Serial.begin(115200);   
  pinMode(LED_BUILTIN, OUTPUT); // Set the pin as output
  Serial.printf("--Setup-OLED free heap: %d, minimum ever free heap: %d", xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize());  
  setup_oled();  
  Serial.printf("--Setup-MESH--current free heap: %d, minimum ever free heap: %d", xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize());
  //delay(100);  
  //pinMode(0,GPIO_MODE_OUTPUT); // Set the pin as output   
  //delay(100);
  setup_mesh();
  Serial.printf("--Setup-BLE--current free heap: %d, minimum ever free heap: %d", xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize());
  setup_ble();
  Serial.printf("--Setup-DONE--current free heap: %d, minimum ever free heap: %d", xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize());

  
}

void setup_mesh(){
  Serial.println("-----MESH Init");
  //mesh.setDebugMsgTypes(ERROR |STARTUP);  // set before init() so that you can see startup messages // CONNECTION |
  //TODO.. make configurable
  mesh.init(MESH_SSID, MESH_PASSWORD, &taskScheduler, MESH_PORT);
  Serial.println("-----MESH Init called");
  //TODO.. make configurable
  mesh.setName(nodeName); // This needs to be an unique name! 
  Serial.println("-----MESH setName");
  mesh.onReceive([](uint32_t from, String &msg) {
    digitalWrite(LED_BUILTIN, HIGH); //Turn on
    Serial.printf("Received message by id from: %u, %s\n", from, msg.c_str());
    digitalWrite(LED_BUILTIN, LOW); //Turn offf

    //TODO SEND TO MESH LEAF OVER HC-12 or RA-2
  });

  mesh.onReceive([](String &from, String &msg) {
    digitalWrite(LED_BUILTIN, HIGH); //Turn on
    Serial.printf("Received message by name from: %s, %s\n", from.c_str(), msg.c_str());
    digitalWrite(LED_BUILTIN, LOW); //Turn offf

    //TODO SEND TO MESH LEAF OVER HC-12 or RA-2
  });

  mesh.onChangedConnections([]() {
    Serial.printf("Changed connection\n");
  });
 
  Serial.println("-----MESH Init complete");
  
}

void setup_ble(){
  Serial.println("-----BLE Init");
  BLEDevice::init("esp32");
  pBLEScan = BLEDevice::getScan(); //POINTER IS CORRUPTED
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99);  // less or equal setInterval value
  taskScheduler.addTask(taskBLEScanner);
  taskBLEScanner.enable();
}

// Adapted from Adafruit_SSD1306
void drawLines() {
  display.clear();
}

void setup_oled(){
  Serial.println("-----Setting up OLED");
  display.init();
  display.setI2cAutoInit(true);
  display.flipScreenVertically();

  display.setContrast(255);
  display.clear();
  
}

void loop() {
  mesh.update();  
}

Who is online

Users browsing this forum: No registered users and 68 guests