Hi there,
I’m a newbie in FreeRTOS and at my second “real” project using it, i’m still trying to understand
- How much size should the task stack have
- What does the task stack actually hold
For context, the device is a dsPIC33CK and i am using the Microchip Port for freeRTOS v9 present on their github —> GitHub - MicrochipTech/freeRTOS-PIC24-dsPIC-PIC32MM: This repository contains the freeRTOS demos for Microchip device families like PIC24, dsPIC33E, dsPIC33F , dsPIC33C and PIC32MM.
compiler is XC16 v1.70
(by the way, the main site and official repo demos should really be updated to use current development tools)
In my project i do not use the heap, but all tasks, queues etc are created using the “static” api calls.
Now, to my question: it was my understanding that automatic variables created inside a task would be allocate inside the task’s stack so let’s take this code
//There will be a 256 byte buffer
#define BUFSIZE 256UL
//The stack size will be of 300 words - 600bytes in the dsPIC port (machine word is 16bit!)
#define STACKSIZE 300
StaticTask_t xTaskBuffer;
StackType_t xTaskStack[STACKSIZE];
void vTaskCreate(void) {
xTaskCreateStatic(&vTask,
"TASK",
STACKSIZE,
NULL,
configMAX_PRIORITIES-1,
xTaskStack,
&xTaskBuffer);
}
void vTask(void *prvTaskData) {
uint8_t buf[BUFSIZE];
while(true) {
//Do stuff
}
}
To my understanding the address of “buf” should be between the address of xTaskStack and that plus 600bytes.
Instead i see in the debugger that
xTaskStack is at address 0x14CE
buf is at address 0x13C4, 266 bytes before
Also, checking with the FreeRTOS Viewer plugin in MPLABX shows stack usage of 71 words, same as the idle task
What am i missing here?