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.
I had a quick question regarding the stack pointer initialization address for the MSP430G2553. I am aware that there is some leeway in initialization, but am hoping to find a "best practice" approach. In the training videos and documentation, TI suggests initializing the stack pointer to the beginning of RAM (#0200h for this chip), which makes sense to me if there is no need to place it in another location.
However, in all of TI's example ASM code that I have reviewed, TI initializes the stack pointer to #0280h. Is there a particular reason that this address is preferred? I cannot find anything special about it, as it seems to be just another RAM address per the memory map, albeit offset by 128 bits.
Thanks in advance.
Edit: Changed generalizations regarding "all" TI examples to cover only those I have personally reviewed.
MSP430G2553 has 512 bytes (256 words) of RAM at address from 0x0200 to 0x03FF. The usual practice is to initialize the SP to point to 0x0400 and assign static variables starting at 0x200 and progressively higher addresses. Doing it this way, you have the following situation:
a. If you have no static variable at all, then the stack has room for 256 words before it overflows.
b. If you have 1 or 2 bytes of static variables instead, then the stack is limited to have 255 words. (The next item on the stack will wipe out your static variables.)
c. If you have 3 or 4 bytes of static variables, then the stack is limited to have 254 words.
d. ... If you have 509 or 510 bytes of static variables, then the stack can ony have 1 word.
e. If you have 511 or 512 bytes of static variables instead, then the stack cannot be used at all.
Hopefully, you have far less then 512 bytes of static varibles, and there is enough room left for the stack.
Alternatively, you could allocate the highest addressed RAM to your static variables and let the stack use the lower addressed RAM.
a. If you have no static variable, initialize SP to 0x0400.
b. If you have 1 or 2 bytes of static variable, assign them to 0x03FE and 0x03FF. Initialize SP to 0x03FE.
c. If you have 3 or 4 bytes of static variable, assign them from 0x03FC up to 0x03FF. Initialize SP to 0x03FC.
d. ... If you have 509 or 510 bytes of static variable, assign them from 0x0202 up to 0x3FF. Initialize SP to 0x202.
Doing it this way, your over-grown stack will not wipe out your static varibles but overflow into no RAMs land and probably cause a crash later.
**Attention** This is a public forum