AnsweredAssumed Answered

Stack Location

Question asked by Joseph Kissell on Jul 29, 2015
Latest reply on Jul 31, 2015 by Joseph Kissell

It seems to me that the standard in embedded programming is to have the stack start at the end of RAM.


I've been using a new approach for awhile now that seems to work much better. Please tell me if this is a known strategy that others use and if it has any negative consequences I may have overlooked.


I setup the stack to be located at the start of RAM. With this approach, if the stack ever overflows, it attempts to access protected registers (at least in the Kinetis MCU's I've been using) and therefore causes a hard-fault which is easy to catch and handle gracefully. If that same scenario occurs in the standard/traditional method, the stack can overflow into RAM and cause the code to run-away with unexpected behavior which is simply unacceptable, and even dangerous, in safety critical applications.