15.3.2 Estimating Stack Usage

In a bare-metal embedded application, the application developer must determine an appropriate minimum amount of data RAM to reserve for the stack and pass that value to the XC32 linker. The linker then uses this value to ensure that sufficient RAM is reserved for the stack.

However, due to reasons described later, the exact stack requirements of an application can be determined only at runtime. At link time, XC32 can use static analysis to estimate the maximum stack size required by the application and provide guidance in a human-readable report. It does this by computing the stack usage of each function and then using application's call graph to find the largest stack usage.

Generally speaking, this report cannot provide you with an exact value, but it provides you with information that you can use to determine an appropriate size for your stack reservation. Only you understand the precise system-level, runtime behavior of your application.