arduino-esp32
arduino-esp32 copied to clipboard
External ram allocation fail on one esp32 but not on the others?
Board
esp-wrover-kit
Device Description
esp32-wrover-e ( 8mb psram 16mb flash )
Hardware Configuration
ETH_Lan8720, DS3231 (i2c), Heavy serial 1 ( modbus ), SPI display
Version
latest development Release Candidate (RC-X)
IDE Name
Platform IO
Operating System
Windows 10
Flash frequency
80Mhz
PSRAM enabled
yes
Upload speed
115200
Description
External ram memory allocation assert fail. Happens on one esp32-wrover-e but not on others with the exact same sketch. How to capture the exception?
Sketch
// Crash is at total random allocations but all looks like this ( using ArduinoJSON ):
#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);}
};
using SpiRamJsonDocument = BasicJsonDocument<SpiRamAllocator>;
SpiRamJsonDocument data(DATA_SIZE);
// Example function when using SpiRamJsonDocument:
#define GRAPH_SIZE 20000
char * graph;
graph = (char *) ps_malloc (GRAPH_SIZE * sizeof (char));
void thermSystem::trimGraph(){
// Check if previous allocation was a success.
if( graph == NULL ) { Serial.println("Failed to allocate memory for graph data"); return; }
SpiRamJsonDocument allGraphData(GRAPH_SIZE);
DeserializationError error = deserializeJson(allGraphData, (const char *)graph, GRAPH_SIZE);
if (!error) {
// Get only the graph where the zoneID matches.
JsonObject graphData = allGraphData[zoneID];
if( !graphData.isNull() ){
if( serializeJson(graphData, graph, GRAPH_SIZE) ) {
#if THERM_DEBUG
Serial.printf("Trimmed graph\n");
#endif
}
}
}else{
#if THERM_DEBUG
Serial.printf("Failed to deserialize ALL therm graph. Error: %s\n",error.c_str());
#endif
}
}
Debug Message
E (1851) gpio: gpio_set_level(226): GPIO output gpio_num error
E (1851) gpio: gpio_set_level(226): GPIO output gpio_num error
assert failed: block_trim_free heap_tlsf.c:377 (block_is_free(block) && "block must be free")
Backtrace:0x40083cbd:0x3ffd57f00x4008ece5:0x3ffd5810 0x400944d9:0x3ffd5830 0x40093621:0x3ffd5960 0x40093e67:0x3ffd5980 0x400940e8:0x3ffd59a0 0x400840a2:0x3ffd59c0 0x400840b5:0x3ffd59f0 0x400d2b8a:0x3ffd5a10 0x400dd47e:0x3ffd5a30 0x400dd4e1:0x3ffd5aa0 0x400ddb01:0x3ffd5ac0 0x400f42aa:0x3ffd5b00 0x400f484a:0x3ffd5d90 0x400f487b:0x3ffd5db0 0x400f48e9:0x3ffd5dd0
#0 0x40083cbd:0x3ffd57f0 in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:402
#1 0x4008ece5:0x3ffd5810 in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/esp_system.c:128
#2 0x400944d9:0x3ffd5830 in __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c:85
#3 0x40093621:0x3ffd5960 in block_locate_free at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_tlsf.c:447
(inlined by) tlsf_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_tlsf.c:757
#4 0x40093e67:0x3ffd5980 in multi_heap_malloc_impl at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap.c:197
#5 0x400940e8:0x3ffd59a0 in multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c:230
(inlined by) multi_heap_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/multi_heap_poisoning.c:219 #6 0x400840a2:0x3ffd59c0 in heap_caps_malloc_base at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:147
#7 0x400840b5:0x3ffd59f0 in heap_caps_malloc at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/heap/heap_caps.c:167 #8 0x400d2b8a:0x3ffd5a10 in SpiRamAllocator::allocate(unsigned int) at src/utilities/globals.h:8
(inlined by) ArduinoJson6192_F1::AllocatorOwner<SpiRamAllocator>::allocate(unsigned int) at lib/ArduinoJson-6.x/src/ArduinoJson/Document/BasicJsonDocument.hpp:20
(inlined by) ArduinoJson6192_F1::BasicJsonDocument<SpiRamAllocator>::allocPool(unsigned int) at lib/ArduinoJson-6.x/src/ArduinoJson/Document/BasicJsonDocument.hpp:137
(inlined by) ArduinoJson6192_F1::BasicJsonDocument<SpiRamAllocator>::BasicJsonDocument(unsigned int, SpiRamAllocator) at lib/ArduinoJson-6.x/src/ArduinoJson/Document/BasicJsonDocument.hpp:44
#9 0x400dd47e:0x3ffd5a30 in shutterSys::trimSunGraph() at src/utilities/components/shuttersGraph.cpp:55
#10 0x400dd4e1:0x3ffd5aa0 in shutterSys::loadSunCycles() at src/utilities/components/shuttersGraph.cpp:12
#11 0x400ddb01:0x3ffd5ac0 in shutterSys::update(ArduinoJson6192_F1::ObjectRef, char const*, int, char const*) at src/utilities/components/shuttersInit.cpp:53
#12 0x400f42aa:0x3ffd5b00 in zSystem::createComponents(int) at src/utilities/zones.cpp:284
#13 0x400f484a:0x3ffd5d90 in zSystem::readSavedZones() at src/utilities/zones.cpp:113
#14 0x400f487b:0x3ffd5db0 in zSystem::setup() at src/utilities/zones.cpp:76
#15 0x400f48e9:0x3ffd5dd0 in zonesTask(void*) at src/utilities/zones.cpp:822
ELF file SHA256: 0000000000000000
Rebooting...
Other Steps to Reproduce
I'm using ArduinoJsonAllocator for a lot of JSON serialization / deserialization. This error happens on only one esp32 ( tested on 5 chip with the exact same parameters )
I can not capture this exception because it happens internally.
Error:
assert failed: block_trim_free heap_tlsf.c:377 (block_is_free(block) && "block must be free")
I have found two issues that stated that problem but it seems to me that it was patched a long time ago.
I have a check in setup which looks like this but it did not help:
void setup() {
Serial.begin(115200,SERIAL_8N1,DEBUG_RX,DEBUG_TX);
vTaskDelay(1000);
// The following line evaulates to true.
if( !psramFound() ){
Serial.println("Something wrong with the external ram.");
while(1){ vTaskDelay(1); }
}
}
I have checked existing issues, online documentation and the Troubleshooting Guide
- [X] I confirm I have checked existing issues, online documentation and Troubleshooting guide.