cancel
Showing results for 
Search instead for 
Did you mean: 

function depth support

vchau.2
Associate III

Hi All,

I want to know what is maximum function depth supported by STM32F417 in stmcube ide?

how function depth managed by stack pointer? 

6 REPLIES 6
Ozone
Lead II

This is not exactly "function depth".

But yes, the critical parameter here is stack size, which is part of the specific project settings.
I don't use CubeIDE, so here an example from another toolchain / IDE:

Ozone_0-1734677418484.png

In most cases, stack size is a parameter retrieved or shown during project creation, a.k.a. "project wizard".
Usually a default setting is presented you can edit at that time, or later on.

vchau.2
Associate III

thanks for quick reply,

but my question in not belong to Stack size or stack over flow,

my Questions is -

1. how many C functions can be call in nested form?

2. How stack manage these nested functions by stack pointers

example:

int main()

{

func_1();

}

void func_1();

{

void func_2();

.

.

 

}

There is no limit. The stack may overflow at run-time and this is not automatically detected and in your responsibility.

Here is a recursive function:

 

 

int ackermann(int n, int m) {
  if (n == 0)
    return m + 1;
  else if (m == 0)
    return ackermann(n - 1, 1);
  else
    return ackermann(n - 1, ackermann(n, m - 1));
}

 

 

ackermann(3,6) is 509. Calculating this results involves 2.986.490 recursive function calls (without optimizations). Finding the max. stack size used is left an exercise.

Learning abaout the stack in Cortex-M is a covered in books like "Definitve Guide..." by Joseph Yiu and online: 

Happy reading

KnarfB

thanks for sharing such informative links....

that will be helpfull

> 1. how many C functions can be call in nested form?

As much as the stack size allows.

In general, toolchains/IDEs are really bad at guessing runtime stack sizes. Set to a ball park figure according to code complexity, and increase if you encounter runtime overflows.
Standard library functions (like "printf()") have a significant impact, be aware.

Many RTOSes provide a runtime stack check option for their tasks, as a side note.


@vchau.2 wrote:

2. How stack manage these nested functions by stack pointers


That part is just standard Computer Science - nothing specific to CubeIDE or STM32.

It isn't even specific to C.

https://en.wikipedia.org/wiki/Stack_(abstract_data_type)#Compile-time_memory_management