@@ -91,6 +91,29 @@ int dbgHeapUsed(void)
91
91
return (mallinfo ()).uordblks ;
92
92
}
93
93
94
+ int dbgStackTotal (void )
95
+ {
96
+ return ((uint32_t ) __StackTop) - ((uint32_t ) __StackLimit);
97
+ }
98
+
99
+ int dbgStackUsed (void )
100
+ {
101
+ enum { STACK_PATTERN = 0xADADADAD };
102
+
103
+ uint32_t * p_start = (uint32_t *) &__StackLimit;
104
+ uint32_t * p_end = (uint32_t *) &__StackTop;
105
+
106
+ uint32_t * p_buf = p_start;
107
+ while ( *p_buf == STACK_PATTERN && p_buf != p_end)
108
+ {
109
+ p_buf++;
110
+ }
111
+
112
+ if (p_buf == p_end) return (-1 );
113
+
114
+ return ((uint32_t ) p_end) - ((uint32_t ) p_buf);
115
+ }
116
+
94
117
static void printMemRegion (const char * name, uint32_t top, uint32_t bottom, uint32_t used)
95
118
{
96
119
char buffer[30 ];
@@ -111,10 +134,10 @@ void dbgMemInfo(void)
111
134
Serial.println (" | |" );
112
135
113
136
// Pritn SRAM used for Stack executed by S132 and ISR
114
- printMemRegion (" Stack" , ((uint32_t ) __StackTop), ((uint32_t ) __StackLimit), 0 );
137
+ printMemRegion (" Stack" , ((uint32_t ) __StackTop), ((uint32_t ) __StackLimit), dbgStackUsed () );
115
138
116
139
// Print Heap usage overall (including memory malloced to tasks)
117
- printMemRegion (" Heap" , ((uint32_t ) __HeapLimit), ((uint32_t ) __HeapBase), dbgHeapUsed ());
140
+ printMemRegion (" Heap" , ((uint32_t ) __HeapLimit), ((uint32_t ) __HeapBase), dbgHeapUsed () );
118
141
119
142
// DATA + BSS
120
143
printMemRegion (" Data & Bss" , ((uint32_t ) __bss_end__), ((uint32_t ) __data_start__), 0 );
0 commit comments