This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Configuring stack size and direction to avoid stack overflow

Hello,

I'm using a Cortex M-4 processor (STM32F4) and I recently encountered strange behavior of my code after minor modifications that were not directly related to the problems I was seeing.

After a bit of digging, I noticed that some of my global variables were modified without being accessed through the code. Looking at the memory mapping, it turned out these variables were located just before the stack. Increasing the stack size in the startup file solved the issue, so obviously this was a stack overflow.

But the thing is, I want to be sure that when a stack overflow occurs, a fault happens, not some random behavior. I thought I was safe because my stack was at the end of the RAM space. But as it turns out, it actually grows backwards.

So the question is: How to configure the stack direction ? And are there other ways to prevent this kind of problem?

Thank you