Improvements to heap-memory and PSRAM handling (#4791)
* Improved heap and PSRAM handling - Segment `allocateData()` uses more elaborate DRAM checking to reduce fragmentation and allow for larger setups to run on low heap - Segment data allocation fails if minimum contiguous block size runs low to keep the UI working - Increased `MAX_SEGMENT_DATA` to account for better segment data handling - Memory allocation functions try to keep enough DRAM for segment data - Added constant `PSRAM_THRESHOLD` to improve PSARM usage - Increase MIN_HEAP_SIZE to reduce risk of breaking UI due to low memory for JSON response - ESP32 makes use of IRAM (no 8bit access) for pixeluffers, freeing up to 50kB of RAM - Fix to properly get available heap on all platforms: added function `getFreeHeapSize()` - Bugfix for effects that divide by SEGLEN: don't run FX in service() if segment is not active -Syntax fix in AR: calloc() uses (numelements, size) as arguments * Added new functions for allocation and heap checking - added `allocate_buffer()` function that can be used to allocate large buffers: takes parameters to set preferred ram location, including 32bit accessible RAM on ESP32. Returns null if heap runs low or switches to PSRAM - getFreeHeapSize() and getContiguousFreeHeap() helper functions for all platforms to correctly report free useable heap - updated some constants - updated segment data allocation to free the data if it is large - replaced "psramsafe" variable with it's #ifdef: BOARD_HAS_PSRAM and made accomodating changes - added some compile-time checks to handle invalid env. definitions - updated all allocation functions and some of the logic behind them - added use of fast RTC-Memory where available - increased MIN_HEAP_SIZE for all systems (improved stability in tests) - updated memory calculation in web-UI to account for required segment buffer - added UI alerts if buffer allocation fails - made getUsedSegmentData() non-private (used in buffer alloc function) - changed MAX_SEGMENT_DATA - added more detailed memory log to DEBUG output - added debug output to buffer alloc function
This commit is contained in:
@@ -812,7 +812,7 @@ void serializeInfo(JsonObject root)
|
||||
root[F("clock")] = ESP.getCpuFreqMHz();
|
||||
root[F("flash")] = (ESP.getFlashChipSize()/1024)/1024;
|
||||
#ifdef WLED_DEBUG
|
||||
root[F("maxalloc")] = ESP.getMaxAllocHeap();
|
||||
root[F("maxalloc")] = getContiguousFreeHeap();
|
||||
root[F("resetReason0")] = (int)rtc_get_reset_reason(0);
|
||||
root[F("resetReason1")] = (int)rtc_get_reset_reason(1);
|
||||
#endif
|
||||
@@ -823,15 +823,15 @@ void serializeInfo(JsonObject root)
|
||||
root[F("clock")] = ESP.getCpuFreqMHz();
|
||||
root[F("flash")] = (ESP.getFlashChipSize()/1024)/1024;
|
||||
#ifdef WLED_DEBUG
|
||||
root[F("maxalloc")] = ESP.getMaxFreeBlockSize();
|
||||
root[F("maxalloc")] = getContiguousFreeHeap();
|
||||
root[F("resetReason")] = (int)ESP.getResetInfoPtr()->reason;
|
||||
#endif
|
||||
root[F("lwip")] = LWIP_VERSION_MAJOR;
|
||||
#endif
|
||||
|
||||
root[F("freeheap")] = ESP.getFreeHeap();
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
if (psramFound()) root[F("psram")] = ESP.getFreePsram();
|
||||
root[F("freeheap")] = getFreeHeapSize();
|
||||
#if defined(BOARD_HAS_PSRAM)
|
||||
root[F("psram")] = ESP.getFreePsram();
|
||||
#endif
|
||||
root[F("uptime")] = millis()/1000 + rolloverMillis*4294967;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user