Hi Folks,
I've been writing a fairly large sketch which has functions that call other functions several times deep. They're not recursive, but say about 7-subroutines deep. From what I understand about the stack, is that all the register values are pushed onto the stack each time a new method is called. Are all the local variables from the calling method also pushed onto the stack as well? They must-- I don't see how we'd keep track of local variables otherwise.
I understand that the stack starts at the highest SRAM address and grows downward, whereas the regular Data Memory starts just after all the External IO Registers and grows upward. Eventually, as SRAM usage grows, the heap space and the stack space collide.
The reason I ask is because once I reached a certain method-depth, the program ceases to function correctly... if at all. I assume that the heap data has over-written part of the stack, and thus a return value is no longer valid. From my previous programming experience, it was good practice to use local variables wherever possible... but with such limited stack space, and no warning that stack corruption is taking place, I'm unsure if there's a better way to handle this.
Is there a way to set a maximum stack size? Or to limit the area of SRAM which can be used for the heap? How do the advanced users out there deal with these issues?