From 37f320c353ec3435015423fb5ed85b3759a0300b Mon Sep 17 00:00:00 2001 From: folkert van heusden Date: Sun, 5 May 2024 19:33:24 +0200 Subject: [PATCH] leave 32 kB PSRAM to the SDK; the adafruit qty s3 goes into a reboot-loop with all PSRAM allocated --- ESP32/main.ino | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ESP32/main.ino b/ESP32/main.ino index 7b0f2ef..99e7c73 100644 --- a/ESP32/main.ino +++ b/ESP32/main.ino @@ -289,10 +289,14 @@ void setup() { Serial.println(ESP.getFreeHeap()); if (psramInit()) { + constexpr const uint32_t leave_unallocated = 32768; + uint32_t free_psram = ESP.getFreePsram(); - n_pages = min(free_psram / 8192, uint32_t(256)); // start size is 2 MB max (with 1 MB, UNIX 7 behaves strangely) - Serial.printf("Free PSRAM: %d decimal bytes (or %d pages (see 'ramsize' in the debugger))", free_psram, n_pages); - Serial.println(F("")); + if (free_psram > leave_unallocated) { + n_pages = min((free_psram - leave_unallocated) / 8192, uint32_t(256)); // start size is 2 MB max (with 1 MB, UNIX 7 behaves strangely) + Serial.printf("Free PSRAM: %d decimal bytes (or %d pages (see 'ramsize' in the debugger))", free_psram, n_pages); + Serial.println(F("")); + } } #endif