ph1p / ikea-led-obegraensad

ESP32/Arduino hack for the ikea OBEGRÄNSAD led wall lamp
MIT License
578 stars 78 forks source link

Crash Loop on ESP32-S3-WROOM-1-N8R8 #71

Open Jotschi opened 7 months ago

Jotschi commented 7 months ago

I'm currently trying to narrow it down but I believe the error happens when sendInfo of websocket.cpp is invoked.

assert failed: insert_free_block heap_tlsf.c:233 (current && "free list cannot have a null entry")

The S3 N8R8 has 8MB PSRAM.

Jotschi commented 7 months ago

Update: I was able to fix/workaround the issue by adding a custom allocator which uses SPI and the PSRAM for the JSON document:

#include <Arduino.h>
#include <ArduinoJson.h>

struct SpiRamAllocator {
  void* allocate(size_t size) {
    return heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
  }

  void deallocate(void* pointer) {
    heap_caps_free(pointer);
  }

  void* reallocate(void* ptr, size_t new_size) {
    return heap_caps_realloc(ptr, new_size, MALLOC_CAP_SPIRAM);
  }
};

Details: https://arduinojson.org/v6/how-to/use-external-ram-on-esp32/

Unfortunately now the ESP32 crashes when I try to invoke the first request.

assert failed: spinlock_acquire spinlock.h:122 (result == core_id || result == SPINLOCK_FREE)

Returning a basic hello world works.