Browse Source

ESP::ps_malloc check mem availability before allocation.

v0.9.4
Guy Turcotte 3 years ago
parent
commit
8f6d6e9aee
  1. 7
      include/services/esp.hpp

7
include/services/esp.hpp

@ -60,8 +60,11 @@ class ESP
return adc1_get_raw(channel);
}
static void * ps_malloc(uint32_t size) {
void * mem = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
static void * ps_malloc(uint32_t size) {
void * mem = nullptr;
if (heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM) > size) {
mem = heap_caps_malloc(size, MALLOC_CAP_SPIRAM);
}
if (mem == nullptr) {
ESP_LOGE(TAG, "Not enough memory on PSRAM!!! (Asking %u bytes)", size);
}

Loading…
Cancel
Save