This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Reaction on stack overflow

Other Parts Discussed in Thread: MSP430G2553

Hi!

I am using the MSP430G2553 and it has a very small RAM (512B).

My question is, how reacts the MSP when the stack reaches the end of RAM?

Kind regards

Paul

  • Paul Fey said:
    My question is, how reacts the MSP when the stack reaches the end of RAM?

    msp430 itself continues to operate as expected, your application most probably not. When stack reaches end of RAM - it means that all your variables are corrupted. What exactly will happen - it's up to your code that uses such corrupt data.

  • Hi Ilmars,

    and where does the stackpointer points to?

    Behind the RAM the peripherals starts? And if the CPU fetch something from there a PUC is generated?

    Kind regards

    Paul

  • The Stack is on top of RAM and grows downwards. If you run-out of stack it first starts to attack you RAM-data but before it comes to the end of RAM your program will be probably already crashed. To easily check stack-use add the following lines to your program, immediately at the begin of main and just after stopping the watchdog. Let the program run a while and stop it, check the stack contents with the memory-browser, if all A5 are gone you can be sure you have a stack overflow and needs to increase stack-size.

    	extern unsigned int _stack;
    	extern unsigned int __STACK_END;
    
    	unsigned int* p = &_stack;
    
    	// Fill Stack with 0xA5A5
    	while (p < (&__STACK_END +1)) {*p++ = 0xA5A5;}
    

     

  • Paul Fey said:
    Behind the RAM the peripherals starts? And if the CPU fetch something from there a PUC is generated?

    Yes, peripheral registers are there. However as return addresses are pushed on stack, I can't tell what exactly will happen when stack goes into peripheral address range - because registers happen to behave like RAM. Most probably sooner or later CPU will fetch some address that does not belong to RAM or code flash and reset will be generated in result.

    Why you ask? It's homework question I just answered?

  • Ahm no!

    I try to understand the information from the MSP430x2xx Family users guide and not the basic function of the stack.

    The users guide says:

    The following events trigger a PUC:
    • ...
    • A CPU instruction fetch from the peripheral address range 0h to 01FFh

    That means, if the SP points to an address outside of the RAM a PUC is set?! Everything works fine till this point and no data are corrupted! After this point the system restart? 

    My question is:

    is it true, that  when an overflow occures the system restarts??  

  • Paul Fey said:
    That means, if the SP points to an address outside of the RAM a PUC is set?

    Maybe yes, maybe not. - Because stack does not contain instructions but pointers to them. Stack push of return address possibly can be successful even if SP points to peripheral register address, also POP operation can give address in RAM or code flash range.

    So you can't say for sure that PUC will be generated if SP goes into peripheral register address range.

  • Paul Fey said:

    I try to understand the information from the MSP430x2xx Family users guide and not the basic function of the stack.

    The users guide says:

    You should have included that statement in the first post.

**Attention** This is a public forum