title: FreeRTOS - The reason for the stack increase?
body: <p>I have created several tasks, the body of which is the same function. Inside the function, there is a delay that is the same for every task. So, when this delay is large enough, the stack of each task is filled with 6 words less than when the delay is less.
  As far as I understand, the stack of tasks increases when there is a situation with several tasks with the status <code>Ready</code>.</p>
  <p>1.In this situation, some additional 6-word context is written to the task stack?</p>
  <p>2.In my example, it turns out 6 words (24 bytes), can this value change somehow?</p>
  <p>3.What else can affect the increase in the stack, such as jumping into an interrupt handler?</p>
  <pre><code>int main(void){
    xTaskCreate(Task_PrintCountString, &quot;Task_1&quot;, mySTACK_SIZE, &amp;param1, 1, NUUL);
    xTaskCreate(Task_PrintCountString, &quot;Task_2&quot;, mySTACK_SIZE, &amp;param2, 1, NUUL);
    xTaskCreate(Task_PrintCountString, &quot;Task_3&quot;, mySTACK_SIZE, &amp;param3, 1, NUUL);
    vTaskStartScheduler();
  }
  #define myDELAY     100
  void Task_PrintCountString(void *pParams){
    uint16_t c=0; 
    for(;;){
      if(xSemaphoreTake(WriteCountMutex, portMAX_DELAY) == pdTRUE){
          PrintCountString(*(uint8_t *)pParams, c++);
          xSemaphoreGive(WriteCountMutex);
      }       
    vTaskDelay(myDELAY/portTICK_PERIOD_MS);//When myDELAY=1, the task stack is 6 words more than when myDELAY= 100!       
    } 
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/vnYjg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vnYjg.jpg" alt="enter image description here" /></a></p>
  <p>Address 0x20000158 is the top of the stack for one of the tasks. Similarly, others!</p>
  <p>The only function <code>PrintCountString</code> always the same depth. But at the same time, the stack can grow to its maximum knowledge in several stages, going through dozens of iterations of the task cycle! It turns out that not only the context is saved to the stack, but something else?</p>
  <p>P.S.
  I use <code>ARM CM0 port</code> and <code>heap_1</code>.</p>
  <p>I made an observation:
  In the <code>PrintCountString</code> function there was a block for waiting for the SPI flag - <code>while()</code>. I replaced the DMA transfer method and removed the <code>while()</code> loop. The stack of both tasks began to fill up immediately to the maximum value, regardless of delays.</p>