diff --git a/sonoff/xdrv_99_debug.ino b/sonoff/xdrv_99_debug.ino index 5aa1f4231..8a167511c 100644 --- a/sonoff/xdrv_99_debug.ino +++ b/sonoff/xdrv_99_debug.ino @@ -180,6 +180,9 @@ void CpuLoadLoop() /*******************************************************************************************/ +#if defined(ARDUINO_ESP8266_RELEASE_2_3_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_0) || defined(ARDUINO_ESP8266_RELEASE_2_4_1) +// All version before core 2.4.2 + extern "C" { #include extern cont_t g_cont; @@ -198,6 +201,28 @@ void DebugFreeMem() AddLog(LOG_LEVEL_DEBUG); } +#else +// All version from core 2.4.2 +// https://github.com/esp8266/Arduino/pull/5018 +// https://github.com/esp8266/Arduino/pull/4553 + +extern "C" { +#include + extern cont_t* g_pcont; +} + +void DebugFreeMem() +{ +// https://github.com/esp8266/Arduino/issues/2557 + register uint32_t *sp asm("a1"); + + snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DEBUG "FreeRam %d, FreeStack %d (%s)"), + ESP.getFreeHeap(), 4 * (sp - g_pcont->stack), XdrvMailbox.data); + AddLog(LOG_LEVEL_DEBUG); +} + +#endif // ARDUINO_ESP8266_RELEASE_2_x_x + /*******************************************************************************************/ void DebugCfgDump(char* parms)