From 82f898fab58cec15a85f01f2b99027e4d4debb78 Mon Sep 17 00:00:00 2001 From: Hieromon Ikasamo Date: Sun, 19 May 2019 06:21:25 +0900 Subject: [PATCH] Added the existence check of PSRAM --- src/AutoConnectJsonDefs.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/AutoConnectJsonDefs.h b/src/AutoConnectJsonDefs.h index a596df2..b1da00a 100644 --- a/src/AutoConnectJsonDefs.h +++ b/src/AutoConnectJsonDefs.h @@ -42,7 +42,14 @@ using ArduinoJsonArray = JsonArray; // JsonDocument is assigned to PSRAM by ArduinoJson's custom allocator. struct SpiRamAllocatorST { void* allocate(size_t size) { - return heap_caps_malloc(size, MALLOC_CAP_SPIRAM); + uint32_t caps; + if (psramFound()) + caps = MALLOC_CAP_SPIRAM; + else { + caps = MALLOC_CAP_8BIT; + AC_DBG("PSRAM not found, JSON buffer allocates to the heap.\n"); + } + return heap_caps_malloc(size, caps); } void deallocate(void* pointer) { heap_caps_free(pointer);