jankok wrote on Tuesday, March 13, 2018:
I’m using an Arduino Uno with the Arduino IDE, using FreeRTOS v10.0.0. The Blink_AnalogRead example runs fine.
When I try to run some code in the loop() function (which I believe is the idle process) and I read the StackHighWaterMark, it sometimes goes to 0 depending on the code I have in the loop() function. Changing configMINIMAL_STACK_SIZE to a larger number has no effect on the StackHighWaterMark, even when it was originally nonzero.
How do I increase the stack space available to the idle process?
Here’s the code I used to test the stack space:
// This function calls itself recursively to a depth of n, and does a simple check
// to try to detect stack corruption.
int memtest(int n)
{
//delay(50);
Serial.print(n); Serial.print(' '); //%10);
if (n%50 == 0) Serial.println("");
int n1;
if (n) {
n1 = memtest(n-1);
if (n1 != (n-1)) {
Serial.println("");
Serial.print("n=");
Serial.print(n);
Serial.print(" n1=");
Serial.println(n1);
while(1) {};
}
}
//delay(50);
Serial.print(n); Serial.print(' ');
if (n%50 == 49) Serial.println("");
return n;
}
void loop(void)
{
#if USE_FreeRTOS
UBaseType_t uxHighWaterMark;
/* Inspect our own high water mark on entering the task. */
uxHighWaterMark = uxTaskGetStackHighWaterMark( NULL );
Serial.print("HighWaterMark ");
Serial.println(uxHighWaterMark);
#endif
Serial.println("hi1");
memtest(3); // <----- this can be 99 no problem without FreeRTOS,
// but with FreeRTOS, 8 causes HighWaterMark to go to 0
Serial.println("hi2");
}