Reuse of IAR cstack and rstack

barbercol_22 wrote on Wednesday, February 13, 2008:

Using IAR and a Atmega 645. The IAR needs space for a cstack and rstack for initialization. The return stack should be completely reusable and most of the cstack is free. I do not want to manually force data to these areas because this could lead to maintenance problems later. Is there a way for the compiler linker to automatically reuse this space?

sotd wrote on Wednesday, February 13, 2008:

No, but there are some hacks you can do.

You can make the idle task stack use the same memory to gain some there.

You can use the linker to allocate the main stack to an area that will get written over once the scheduler starts. If the main stack uses memory that is also used by a task stack then you must ensure that the start of the memory block where the first task context is written is kept clean but only that big.

You can allocate a very small stack, pvPortMalloc() some memory from the heap, point the stack to that so you get a stack big enough to create your tasks, then vPortFree() the memory again when the first task start running. This is probably the easiest.

Im talking GCC here not IAR but should be the same.