diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc0877e1..735667c1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. ## [9.5.0.8] +### Fixed +- Fixed crash when PSRAM is absent and ``BOARD_HAS_PSRAM`` set ## [9.5.0.7] 20210901 ### Added diff --git a/lib/libesp32/Berry/default/be_port.cpp b/lib/libesp32/Berry/default/be_port.cpp index c5458eabd..cca5b3f61 100644 --- a/lib/libesp32/Berry/default/be_port.cpp +++ b/lib/libesp32/Berry/default/be_port.cpp @@ -60,12 +60,10 @@ extern "C" { #ifndef BERRY_LOGSZ #define BERRY_LOGSZ 700 #endif -extern "C" { - extern void *berry_malloc(size_t size); -} + static char * log_berry_buffer = nullptr; static_block { - log_berry_buffer = (char*) berry_malloc(BERRY_LOGSZ); + log_berry_buffer = (char*) malloc(BERRY_LOGSZ); if (log_berry_buffer) log_berry_buffer[0] = 0; } extern void berry_log(const char * berry_buf); diff --git a/tasmota/support_esp.ino b/tasmota/support_esp.ino index babda7bef..7a8a26130 100644 --- a/tasmota/support_esp.ino +++ b/tasmota/support_esp.ino @@ -464,10 +464,21 @@ uint8_t* FlashDirectAccess(void) { return data; } +extern "C" { + bool esp_spiram_is_initialized(void); +} + +// this function is a replacement for `psramFound()`. +// `psramFound()` can return true even if no PSRAM is actually installed +// This new version also checks `esp_spiram_is_initialized` to know if the PSRAM is initialized +bool FoundPSRAM(void) { + return psramFound() && esp_spiram_is_initialized(); +} + // new function to check whether PSRAM is present and supported (i.e. required pacthes are present) bool UsePSRAM(void) { static bool can_use_psram = CanUsePSRAM(); - return psramFound() && can_use_psram; + return FoundPSRAM() && can_use_psram; } void *special_malloc(uint32_t size) { @@ -690,6 +701,7 @@ typedef struct { * patches are present. */ bool CanUsePSRAM(void) { + if (!FoundPSRAM()) return false; #ifdef HAS_PSRAM_FIX return true; #endif diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index 15a5cf519..3dd6da220 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -275,12 +275,13 @@ void setup(void) { } // AddLog(LOG_LEVEL_INFO, PSTR("ADR: Settings %p, Log %p"), Settings, TasmotaGlobal.log_buffer); - AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s"), GetDeviceHardware().c_str()); + AddLog(LOG_LEVEL_INFO, PSTR("HDW: %s %s"), GetDeviceHardware().c_str(), + FoundPSRAM() ? (CanUsePSRAM() ? "(PSRAM)" : "(PSRAM disabled)") : "" ); #ifdef ESP32 - AddLog(LOG_LEVEL_DEBUG, PSTR("HDW: psramFound=%i CanUsePSRAM=%i"), psramFound(), CanUsePSRAM()); + AddLog(LOG_LEVEL_DEBUG, PSTR("HDW: FoundPSRAM=%i CanUsePSRAM=%i"), FoundPSRAM(), CanUsePSRAM()); #endif // ESP32 #if defined(ESP32) && !defined(HAS_PSRAM_FIX) - if (psramFound() && !CanUsePSRAM()) { + if (FoundPSRAM() && !CanUsePSRAM()) { AddLog(LOG_LEVEL_INFO, PSTR("HDW: PSRAM is disabled, requires specific compilation on this hardware (see doc)")); } #endif // ESP32