diff --git a/cores/nRF5/debug.cpp b/cores/nRF5/debug.cpp index 7f194d8f..da725b87 100644 --- a/cores/nRF5/debug.cpp +++ b/cores/nRF5/debug.cpp @@ -90,6 +90,7 @@ int dbgHeapUsed(void) return (mallinfo()).uordblks; } +#if 0 static void printCenter(const char* str, int width) { int lpad = (width-strlen(str))/2; @@ -150,6 +151,54 @@ void dbgMemInfo(void) Serial.println(buf); rtos_free(buf); } +#else + +static void printMemRegion(const char* name, uint32_t top, uint32_t bottom, uint32_t used) +{ + char buffer[30]; + if ( used ) + { + sprintf(buffer, "%lu / %lu (%02lu%%)", used, top-bottom, (used*100)/ (top-bottom)); + }else + { + sprintf(buffer, "%lu", top-bottom); + } + + Serial.printf("| %-10s: %-19s |\n", name, buffer); +} + +void dbgMemInfo(void) +{ + Serial.printf (" _________________________________\n"); + Serial.println("| |"); + + // Pritn SRAM used for Stack executed by S132 and ISR + printMemRegion("Stack", ((uint32_t) __StackTop), ((uint32_t) __StackLimit), 0); + + // Print Heap usage overall (including memory malloced to tasks) + printMemRegion("Heap", ((uint32_t) __HeapLimit), ((uint32_t) __HeapBase), dbgHeapUsed()); + + // DATA + BSS + printMemRegion("Data & Bss", ((uint32_t) __bss_end__), ((uint32_t) __data_start__), 0); + + // Print SRAM Used by SoftDevice + printMemRegion("S132", (uint32_t) __data_start__, 0x20000000, 0); + + Serial.printf("|_________________________________|\n"); + Serial.println(); + + // Print Task list + uint32_t tasknum = uxTaskGetNumberOfTasks(); + char* buf = (char*) rtos_malloc(tasknum*40); // 40 bytes per task + + vTaskList(buf); + + Serial.println("Task State Prio StackLeft Num"); + Serial.println("-----------------------------------"); + Serial.println(buf); + rtos_free(buf); +} +#endif /*------------------------------------------------------------------*/ diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index 1e69edda..09c09167 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -16,6 +16,8 @@ #define ARDUINO_MAIN #include "Arduino.h" +#define MEMINFO_INTERVAL 10000 + // Weak empty variant initialization function. // May be redefined by variant files. void initVariant() __attribute__((weak)); @@ -35,7 +37,15 @@ static void loop_task(void* arg) { loop(); -// if (serialEventRun) serialEventRun(); + #if CFG_DEBUG > 1 // Full Debug + static uint32_t meminfo_ms = 0; + if (meminfo_ms + MEMINFO_INTERVAL < millis()) + { + meminfo_ms += millis(); + Serial.printf("Memory Info (print every %d seconds)\n", MEMINFO_INTERVAL/1000); + dbgMemInfo(); + } + #endif // To compatible with most code where loop is not rtos-aware vTaskDelay(1); //taskYIELD(); diff --git a/libraries/Bluefruit52Lib/library.properties b/libraries/Bluefruit52Lib/library.properties index 959bc4b1..2b40ca42 100644 --- a/libraries/Bluefruit52Lib/library.properties +++ b/libraries/Bluefruit52Lib/library.properties @@ -1,5 +1,5 @@ name=Adafruit BLE Libraries for Bluefruit52 -version=0.1.0 +version=0.2.1 author=Adafruit maintainer=Adafruit sentence=Arduino library for nRF52-based Adafruit Bluefruit LE modules