FreeRtos 或 TI rtos 中堆栈大小的计算

Ash*_*ish 3 stack rtos freertos

最近,我正在使用 FreeRTOS 并创建了一些任务来执行我所需的操作。尽管似乎每次我使用xTaskCreate()TI GUI 配置创建新任务时,我只是尝试将堆栈大小保持为所需的大小,以免堆栈溢出。

有没有办法计算我的任务针对以下事件使用的最大堆栈大小?

  1. 全局变量和局部变量使用的堆栈
  2. 函数最大递归次数所使用的栈
  3. 包括中断上下文切换

小智 5

The compiler, compiler optimisation level, CPU architecture, local variable allocations and function call nesting depth all have a large impact on the stack size. The RTOS has minimal impact. For example, FreeRTOS will add approximately 60 bytes to the stack on a Cortex-M - which is used to store the task's context when the task is not running. Whichever method you use to calculate stack usage in your non-RTOS project can be used in your RTOS project too - then add approximately 60 bytes.

您可以计算这些事情,这在安全关键应用程序中可能很重要,但在其他情况下,更务实的方法是尝试并查看 - 使用 RTOS 的功能来测量实际使用了多少堆栈并使用堆栈溢出检测 - 然后进行调整,直到找到最佳值。 http://www.freertos.org/Stacks-and-stack-overflow-checking.html http://www.freertos.org/uxTaskGetStackHighWaterMark.html