• Join
  • Sign In with my.TI Login
Texas Instruments
  • Products
  • Applications
  • Tools & Software
  • Support & Community
  • Sample & Buy
  • About TI
Sample & Purchase Cart Sample & Purchase Cart
  • Search
  • Advanced
TI E2E™ Community
  • Support Forums
  • Blogs
  • Groups
  • Videos
  • 简体中文
  • More ...
TI Home » TI E2E Community » Support Forums » Microcontrollers » MSP430™ Microcontrollers » MSP430 Ultra-Low Power 16-bit Microcontroller Forum » msp430fg2553 stack pointer
Share
MSP430™ Microcontrollers
  • Forum
  • Announcements
  • E2E Wiki
Options
  • Subscribe via RSS
MSP430 Resources
  • MSP430 Product Folder
  • MSP-EXP430G2 - MSP430 LaunchPad Value Line Development kit
  • MSP430 Getting Started Guide
  • MSP430 Microcontroller Projects
  • More Resources >
  • msp430fg2553 stack pointer

    msp430fg2553 stack pointer

    • Tom Brown1
      Posted by Tom Brown1
      on May 12 2012 09:32 AM
      Prodigy10 points

      How can I change the stack return address to return to a common point.

      I need to eit an interrupt and go to a fixed address.

      many thanks

      tom brown

      tombrown@madasafish.com

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Andy Neil
      Posted by Andy Neil
      on May 12 2012 11:58 AM
      Guru32055 points

      Note that you have posted in the "Make the Switch to TI MCUs Success Stories" forum, but this is not a "success story" - is it?

      Tom Brown1
      How can I change the stack return address to return to a common point.

      This is an extremely common novice question and is (almost) invariably not the way to proceed at all!!

      Tom Brown1
      I need to eit an interrupt and go to a fixed address.

      Please state your actual goal; ie, what you're trying to achieve by this - it is almost certainly not a good way to -proceed!

      http://www.catb.org/~esr/faqs/smart-questions.html#goal

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • TonyKao
      Posted by TonyKao
      on May 12 2012 15:26 PM
      Genius3770 points

      If you're using Chrome then this is done automatically, provided you have the correct interrupt directives. Once the ISR finishes the previous PC is popped and returned to.

      With assembly you only need to add the RETI instruction at the end. See the x2xx family guide for more information on how interrupts are handled.

      Tony

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • TonyKao
      Posted by TonyKao
      on May 12 2012 15:30 PM
      Genius3770 points

      Also there's usually a while(1) loop in the main to catch the returns from interrupt where you can do more logic and processing. 

      Tony

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Roberto Romano
      Posted by Roberto Romano
      on May 13 2012 05:15 AM
      Mastermind7695 points

       Hi, this practice has to be discouraged than you are writing a task switcher on a preemptive OS.

       Changing return address need to know exactly what was in previous routine so a better signal or semaphore or a simple global volatile variable suffice more better and cost of logic is less than changing return value.

       Also program is more and more reliable and readable too.

       When you switch from one executing routine to another post activation code never can be executed and this waste stack space never return usable, new activation code is executed so some new stack is wasted and also some status remain undetermined. After a short while program run out of stack space and your code crash in a bad way.

       _____________________________________________

       _________________________________________________

       As from good programming rules DON'T DO THAT!!!!!! 

       _________________________________________________

       Regards

       Roberto


       Please login & click    Verify Answer    if this post answered your question.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • old_cow_yellow
      Posted by old_cow_yellow
      on May 14 2012 00:18 AM
      Guru26635 points

      You normally exit an ISR with the "RETI" instruction. This will pop the top of stack to SR and pop the next word to PC which brings it back to where it was before the interrupt. It sounds like you do not want that last action and want to go to somewhere else. Thus, thus instead of "RETI", you could do "POP SR" followed by "ADD #2,SP" and "BR #somewhere".

      I do not see anything wrong in doing this. People normally do not do things like this because they normally do not have a need to do it. I would not be surprised at all if someone do have a need to do so under special situations. But I am very surprised that this someone can see the need and yet does not know how to do it. It is not a matter of style, trend, or fashion.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Roberto Romano
      Posted by Roberto Romano
      on May 14 2012 18:26 PM
      Mastermind7695 points

      old_cow_yellow
      It sounds like you do not want that last action and want to go to somewhere else. Thus, thus instead of "RETI", you could do "POP SR" followed by "ADD #2,SP" and "BR #somewhere".

       Hi OCY, see the short example and do some consideration about, using assembly change detail but cannot remove problem:

      ----------------------------------------

      int noo(int x; int y)

       { // <---- prolog executed here

       int a,b,c,d,e;

       .... code ...

       Interrupt is fired HERE <-------

      // epilogue

      }

      int main(void)

      { // <---- prolog executed here

      int a,b,c;

       char str[80];

       // some code here

      a=noop(b,c);

      // epilogue

      }

      ------------------------------------------------------------------------------------------------------------------------------

       Main prologue is executed, stack space and allocated to make space for all variables

       Main code start execution...

       noop called, so return address is on stack with parameters too

       noop prolog is executed, stack space is allocated to make space for local variables and actual parameter preallocated by the call

       -----------> interrupt is fired <--------------

       return stack and status register are on stack but....

       your code remove just them.. and all preallocated spaces? Two or three of these switch run stack out of space!!!!

       No info  on how many and what epilogue to be run to remove correct amount of stack space no way to determine how many return and parameter are on stack.

      .....

       In the case of assembly language some push register are necessary on top of routine so again undefined amount of stack space need to be freed by jump code.

       change of compiler or version also affect amount of space allocated and position of variables.

       I got a package that was modified in this way and was just crashing due to a different version number!!!!

       IS THIS PRACTICE TO BE USED?????

       Sorry but I discourage bad programming practices!!!

       Regards

       Roberto


       Please login & click    Verify Answer    if this post answered your question.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    • Jens-Michael Gross
      Posted by Jens-Michael Gross
      on May 15 2012 13:31 PM
      Guru141810 points

      Roberto Romano
       IS THIS PRACTICE TO BE USED?????

      There is a common usage for this practice: when an OS forcefully kicks a running process. Then allocated memory, the complete stack and all ressources are discarded/freed and the program is terminated, returning to the OS command prompt or such.

      However, on MSP, i tmakes no sense kicking a process. It is as useless as returning form main. If something goes wrong and an emergency exit has to be called, there are two ways to do it: either reset the MSP and try again, or to execute some specific code and then halt in an endless lopp or enter LPM for eternal sleep.

      However, none of the two requires returning from an ISR to somewhere else than you were before the interrupt.

      So you're completely right. The only use of this kind of programming that makes sense on an MSP (as far as I can think) is a task scheduler for multitasking. And indeed I use it for exactly this purpose (not an OS, jsut an isolated multitasking library). Every other problem I ever encountered never required it.

      OCY: In most cases where this kind of technique is requested, people did not fully understand the purpose and scope of an ISR.
      An ISR does its job unnoticed from the current operation (except for the time that passed). Typically, they want to do something in the ISR that does not belong there: changing the main program flow due to an event.
      As you correctly noticed: those who have valid reasons to do such kind of manipulation shouldn't have to ask how it is done. And those who have to ask usually don't really need it. There's a reason why 'goto' doesn't work across function boundaries in the C language standard. The same applies to this kind of stack manipulation on assembly level.

      _____________________________________
      Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.
      If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.

      Report Abuse
      • Reply
      You have posted to a forum that requires a moderator to approve posts before they are publicly available.
    TI E2E™ Community
    • Support Forums
    • Blogs
    • Videos
    • Groups
    • Site Support & Feedback
    • Settings
    TI E2E™ Community Groups
    • TI University Program
    • Make the Switch
    • Microcontroller Projects
    • Motor Drive & Control
    Other Communities
    • Deyisupport
    • Designsomething.org
    • beagleboard.org
    • TI on Element 14
    • TI on TechXchangeSM
    Other Technical & Support Resources
    • WEBENCH® Design Center
    • Product Information Centers
    • Technical Documents
    • TI Design Network
    • TI Technical Articles
    • TI Training

    All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.

    Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms of Use of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms of Use of this site. TI, its suppliers and providers of content reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

    Follow Us Texas Instruments on Facebook Texas Instruments on Twitter Texas Instruments on LinkedIn Texas Instruments on Google+
    TI Worldwide | Contact Us | my.TI Login | Site Map | Corporate Citizenship | mobile m.ti.com (Mobile Version)

    TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs and
    embedded processors, along with software, tools and the industry’s largest sales/support staff.

    © Copyright 1995-2013 Texas Instruments Incorporated. All rights reserved.
    Trademarks | Privacy Policy | Terms of Use