How to use freeRTOS to see the number of stacks after each function call

I have to use freeRTOS for an assignment. I have never used it before. I found this piece of code my teacher has uploaded (see code). I think it would be useful for me to play around with this so I can get better practice with FreeRTOS. The code is supposed to tell me the number of stacks left after each function call. In this example, there is only one function (foo), and it calls itself foo(counter+1). There are 4096 stacks and they should reduce by 32 after each function call.

void foo(int counter) {
printf("foo() called ... count = %d\n", counter);
vTaskDelay(1000);
unsigned int temp = uxTaskGetStackHighWaterMark(nullptr) ;
printf("high stack water mark is %u\n", temp);
foo(counter+1) ;
printf("\n");
}

void task(void *ignore) {
foo(1);
}

void setup() {
// put your setup code here, to run once:
xTaskCreate(&task, "task", 4096, NULL, 5, NULL);
}

void loop() {
}

My problem is that I am getting this as an output from the serial monitor (see image below)


I should be getting something like this:
image
I know that the code is correct because it's a straight-up copy and paste from my professor's demo. so there must be something wrong with my setup. any ideas?
I'm using ESP32 board (DOIT ESP32 DEVKIT V1).

The first thing I would check is the baud rate is the same in the sketch and the serial monitor.

1 Like

Thank you so much!! I added ` Serial.begin(9600);' and it works perfectly now! But it's still a mystery how it worked for my professor even when he didn't have that :thinking:

I figured out why his worked without specifying the baud rate! Ok, so he had specified the upload speed as 115200 in tools>upload speed. Then the serial monitor was also at 115200, so they matched. Therefore he didn't need to specify it in the code.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.