Enable malloc error and stack overflow error detection in FreeRTOS. Count them and display them in the SystemInfo app.

main
Jean-François Milants 2023-03-26 14:53:34 +07:00 committed by JF
parent 1911e2d928
commit 611e0ff768
5 changed files with 42 additions and 13 deletions

@ -79,8 +79,8 @@
/* Hook function related definitions. */ /* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0 #define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0 #define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0 #define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_MALLOC_FAILED_HOOK 0 #define configUSE_MALLOC_FAILED_HOOK 1
/* Run time and task stats gathering related definitions. */ /* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0 #define configGENERATE_RUN_TIME_STATS 0

@ -177,6 +177,8 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen2() {
return std::make_unique<Screens::Label>(1, 5, label); return std::make_unique<Screens::Label>(1, 5, label);
} }
extern int mallocFailedCount;
extern int stackOverflowCount;
std::unique_ptr<Screen> SystemInfo::CreateScreen3() { std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
lv_mem_monitor_t mon; lv_mem_monitor_t mon;
lv_mem_monitor(&mon); lv_mem_monitor(&mon);
@ -188,22 +190,23 @@ std::unique_ptr<Screen> SystemInfo::CreateScreen3() {
"#808080 BLE MAC#\n" "#808080 BLE MAC#\n"
" %02x:%02x:%02x:%02x:%02x:%02x" " %02x:%02x:%02x:%02x:%02x:%02x"
"\n" "\n"
"#808080 LVGL Memory#\n" "\n"
" #808080 used# %d (%d%%)\n" "#808080 Memory heap#\n"
" #808080 max used# %lu\n" " #808080 Free# %d\n"
" #808080 frag# %d%%\n" " #808080 Min free# %d\n"
" #808080 free# %d", " #808080 Alloc err# %d\n"
" #808080 Ovrfl err# %d\n",
bleAddr[5], bleAddr[5],
bleAddr[4], bleAddr[4],
bleAddr[3], bleAddr[3],
bleAddr[2], bleAddr[2],
bleAddr[1], bleAddr[1],
bleAddr[0], bleAddr[0],
static_cast<int>(mon.total_size - mon.free_size), xPortGetFreeHeapSize(),
mon.used_pct, xPortGetMinimumEverFreeHeapSize(),
mon.max_used, mallocFailedCount,
mon.frag_pct, stackOverflowCount
static_cast<int>(mon.free_biggest_size)); );
lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0); lv_obj_align(label, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
return std::make_unique<Screens::Label>(2, 5, label); return std::make_unique<Screens::Label>(2, 5, label);
} }

@ -83,6 +83,7 @@ Pinetime::Drivers::Cst816S touchPanel {twiMaster, touchPanelTwiAddress};
#include "displayapp/DisplayAppRecovery.h" #include "displayapp/DisplayAppRecovery.h"
#else #else
#include "displayapp/DisplayApp.h" #include "displayapp/DisplayApp.h"
#include "main.h"
#endif #endif
Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress}; Pinetime::Drivers::Bma421 motionSensor {twiMaster, motionSensorTwiAddress};
Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress}; Pinetime::Drivers::Hrs3300 heartRateSensor {twiMaster, heartRateSensorTwiAddress};
@ -144,7 +145,17 @@ Pinetime::System::SystemTask systemTask(spi,
fs, fs,
touchHandler, touchHandler,
buttonHandler); buttonHandler);
int mallocFailedCount = 0;
int stackOverflowCount = 0;
extern "C" {
void vApplicationMallocFailedHook() {
mallocFailedCount++;
}
void vApplicationStackOverflowHook(TaskHandle_t /*xTask*/, char */*pcTaskName*/) {
stackOverflowCount++;
}
}
/* Variable Declarations for variables in noinit SRAM /* Variable Declarations for variables in noinit SRAM
Increment NoInit_MagicValue upon adding variables to this area Increment NoInit_MagicValue upon adding variables to this area
*/ */

@ -6,3 +6,6 @@
void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action); void nrfx_gpiote_evt_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action);
void DebounceTimerCallback(TimerHandle_t xTimer); void DebounceTimerCallback(TimerHandle_t xTimer);
extern int mallocFailedCount;
extern int stackOverflowCount;

@ -139,6 +139,18 @@ void DisplayProgressBar(uint8_t percent, uint16_t color) {
} }
} }
int mallocFailedCount = 0;
int stackOverflowCount = 0;
extern "C" {
void vApplicationMallocFailedHook() {
mallocFailedCount++;
}
void vApplicationStackOverflowHook(TaskHandle_t /*xTask*/, char */*pcTaskName*/) {
stackOverflowCount++;
}
}
int main(void) { int main(void) {
TaskHandle_t taskHandle; TaskHandle_t taskHandle;
RefreshWatchdog(); RefreshWatchdog();