From 959d4303d20ed4ddb118afd66eb07435874e77cd Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Mon, 22 Jul 2019 18:56:04 +0200
Subject: [PATCH] feat(epicardium): Enable stack-overflow detection

Signed-off-by: Rahix <rahix@rahix.de>
---
 epicardium/FreeRTOSConfig.h | 7 +++++++
 epicardium/support.c        | 6 ++++++
 2 files changed, 13 insertions(+)

diff --git a/epicardium/FreeRTOSConfig.h b/epicardium/FreeRTOSConfig.h
index 6822b068..b92b12b9 100644
--- a/epicardium/FreeRTOSConfig.h
+++ b/epicardium/FreeRTOSConfig.h
@@ -56,6 +56,13 @@
 /* Allow static allocation of data structures */
 #define configSUPPORT_STATIC_ALLOCATION 1
 
+/*
+ * Enable stack overflow detector.
+ *
+ * TODO: Remove for production.
+ */
+#define configCHECK_FOR_STACK_OVERFLOW 2
+
 /* Alias the default handler names to match CMSIS weak symbols */
 #define vPortSVCHandler       SVC_Handler
 #define xPortPendSVHandler    PendSV_Handler
diff --git a/epicardium/support.c b/epicardium/support.c
index 534506ba..a4af99db 100644
--- a/epicardium/support.c
+++ b/epicardium/support.c
@@ -6,6 +6,7 @@
 #include "task.h"
 
 #include "api/dispatcher.h"
+#include "modules/log.h"
 
 #include "card10.h"
 
@@ -112,3 +113,8 @@ void vApplicationGetTimerTaskMemory(
 	 */
 	*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
 }
+
+void vApplicationStackOverflowHook(TaskHandle_t xTask, signed char *pcTaskName)
+{
+	LOG_CRIT("rtos", "Task \"%s\" overflowed stack!", pcTaskName);
+}
-- 
GitLab