Dear forum members,
On http://www.freertos.org/implementation/index.html I found the really nice explanation about the internals of FreeRTOS, really a good job! I was curious if there was some more in-depth manual about memory management too.
At http://www.freertos.org/FAQMem.html there is something written down, but it is very brief. I have a lot of beginner’s questions w.r.t. debugging an application on top of FreeRTOS. For example I use a call to uxTaskGetStackHighWaterMark to get some grips upon the stack size used by a task. However, that should be used after a task is using a lot of its stack, so if a task doesn’t return, I am too late. Is that possible by the way? Are stacks overrun always detected if the configCHECK_FOR_STACK_OVERFLOW flag is set to 2? And overwrites a task other memory if it overflows, or might it become corrupted?
How exactly does the heap and the stacks relate to each other? The configTOTAL_HEAP_SIZE I set to 20kB of the total of 64kB RAM on my Cortex M3 processor (LM3S8962). So, this means that this amount is available to the “kernel” according to http://www.freertos.org/a00110.html, which however means that also my application / tasks use this heap isn’t it? Currently I am using the second heap strategy, see http://www.freertos.org/a00111.html, is it still possible to use malloc() and free(), or should I really use pvPortMalloc() and pvPortFree()? What does it give me for benefit? In my case I am exclusively accessing those data structures anyway (from one task), so I don’t need them defined as critical sections, isn’t it?
In general I would like some clues about how to start debugging my applications. I have three tasks defined that I can dynamically load, so I can test them separately. Each of those tasks I started with 1kB of stack size? Is that too much? I figure that with 64kB - 20kB I have 44kB left, so I shouldn’t be to conservative to begin with. And 1kB is not a conservative figure isn’t it? The I am using the “arm-none-eabi-gdb” debugger via openocd to connect to my board. Compiling with -g -O0 flags should give me enough debug information I hope. It makes the binary bigger, 125kB, but still much less then the 256kB available.
The problem is that after I start two tasks, the third task doesn’t want to be started. The breakpoint in the debugger is never reached, so it seems. So, there is probably some memory problem. I would appreciate any commentary that can give me some background information about how memory is handled within FreeRTOS. How do I know for example how much a task is using from the heap? If I define the heap as 20kB and 3 tasks use each 1kB for their stack, does that mean that I have 64kB - 23kB = 41kB left, which is not used at all (except for some for the stack for the FreeRTOS scheduler)? How do I know how much overall space is left on the heap?