cancel
Showing results for 
Search instead for 
Did you mean: 

what will happen if a function has many lines in KEIL MDK 5

David.Cheng
Associate II

i have called a function big , and then found some memory overwrite

3 REPLIES 3

Automatic/Local variables reside on the stack, make sure it is adequate for function and everything it calls directly and indirectly. Check size, defined in startup_stm32xxxx.s​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thanks ! i will large it by which rule

Not sure I fully comprehend the response. The routines will use space dependent on your code, understand the memory foot-print of what you're expecting to be allocated. There is a direct cause and effect, if you have 4KB of structures/arrays it has to come from somewhere. One could measure maximal depth by filling the available stack area with a recognizable pattern, and then inspecting with a memory view in debugger. Or have code to measure how much of the pattern remains.

This is not a specifically STM32 or Keil issue, but a general C and micro-controller one.

GNU/GCC hides this somewhat as it puts the stack at the top of available RAM in the STMicro scripts, whereas Keil gives it a defined size, and resides above the heap, locale and statics.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..