diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 4954223..6694244 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -123,8 +123,8 @@ void loop() LCDDisplay::loop(); // ignored if LCD not in use -// Report any decrease in memory (will automatically trigger on first call) - static int ramLowWatermark = 32767; // replaced on first loop + // Report any decrease in memory (will automatically trigger on first call) + static int ramLowWatermark = __INT_MAX__; // replaced on first loop int freeNow = minimumFreeMemory(); if (freeNow < ramLowWatermark) diff --git a/freeMemory.cpp b/freeMemory.cpp index f8d2a0b..f1ad965 100644 --- a/freeMemory.cpp +++ b/freeMemory.cpp @@ -32,7 +32,7 @@ extern char *__malloc_heap_start; #endif -static volatile int minimum_free_memory = 32767; +static volatile int minimum_free_memory = __INT_MAX__; static inline int freeMemory() { @@ -52,6 +52,7 @@ static inline int freeMemory() { // void updateMinimumFreeMemory(unsigned char extraBytes) { int spare = freeMemory()-extraBytes; + if (spare < 0) spare = 0; if (spare < minimum_free_memory) minimum_free_memory = spare; }