CORRUPT HEAP, how to resolve

Posts: 1
Joined: Thu Mar 14, 2019 2:37 pm

CORRUPT HEAP, how to resolve

Postby jeroenb42 » Thu Mar 14, 2019 2:42 pm

I have modified a working arduino code file for the MiFlora (which works, I have a few of these operational) to be able to modify my BLE led bulbs. The code works but after going through it once, it crashes with a CORRUPT HEAP error. I have no idea how to solve this. I have tried a lot of things but cannot figure it out.

My serial output:

Code: Select all

Starting Bluetooth
Trying to form connection to device at fc:58:fa:f1:99:f5
 - Connected
 - Found our service
CORRUPT HEAP: Bad head at 0x3ffdf07c. Expected 0xabba1234 got 0x3ffdfc8c
assertion "head != NULL" failed: file "/Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/heap/multi_heap_poisoning.c", line 214, function: multi_heap_free
abort() was called at PC 0x40148bdb on core 0

Backtrace: 0x4008d8d0:0x3ffd3260 0x4008db01:0x3ffd3280 0x40148bdb:0x3ffd32a0 0x4009302d:0x3ffd32d0 0x40084556:0x3ffd32f0 0x4008a289:0x3ffd3310 0x4000bec7:0x3ffd3330 0x400dbc69:0x3ffd3350 0x400dc6fe:0x3ffd3370 0x400dc7c0:0x3ffd3390 0x40119197:0x3ffd33b0 0x4013810a:0x3ffd33d0 0x40118d72:0x3ffd3660 0x40118eb1:0x3ffd3680 0x4011bed2:0x3ffd36a0 0x400f658a:0x3ffd36c0 0x40092545:0x3ffd36f0

So I put in a lot of Serial.println's to see where the code fails but it seems to fail at something inside the core of arduino. I hope it's just something silly I overlooked. Let me know your thoughts

My program:

Code: Select all

#include "BLEDevice.h"

// The remote service we wish to connect to.
static BLEUUID serviceUUID("0000cc02-0000-1000-8000-00805f9b34fb");

// The characteristic of the remote service we are interested in.
static BLEUUID uuid_onoff("ee03");
static BLERemoteCharacteristic* pRemoteCharacteristic;

bool getSensorData(BLEAddress pAddress) {
  Serial.print("Trying to form connection to device at ");

  BLEClient*  pClient  = BLEDevice::createClient();

  // Connect to the remove BLE Server.
  if (!pClient->connect(pAddress)) {
    return false;
  Serial.println(" - Connected");

  // Obtain a reference to the service we are after in the remote BLE server.
  BLERemoteService* pRemoteService = pClient->getService(serviceUUID);
  if (pRemoteService == nullptr) {
    Serial.print("Failed to find our service UUID: ");
    return false;
  Serial.println(" - Found our service");

  pRemoteCharacteristic = pRemoteService->getCharacteristic(uuid_onoff);
  uint8_t buf[15] = {0,0,1,0,0,0,0,0,1,255};
  pRemoteCharacteristic->writeValue(buf, 10, true);


void setup() {
  Serial.println("Starting Bluetooth");
} // End of setup.

// This is the Arduino main loop function.
void loop() {
  char tmp[20];
  BLEAddress myDevice(tmp);
} // End of loop

Posts: 2148
Joined: Sun May 08, 2016 4:11 am

Re: CORRUPT HEAP, how to resolve

Postby ESP_Angus » Thu Mar 14, 2019 11:59 pm

The error looks like the application may have used more stack than that's available to the task. The task running loop() in Arduino only has 8KB of stack available.

There are two ways to try and solve this.
  • Edit your local copy of main.cpp and change 8192 to a larger number like 16384.
  • Create a second task in your sketch with more stack space and call the BLE function from there.

Who is online

Users browsing this forum: No registered users and 7 guests