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.

TMS320F280039C: How to read stack pointer during runtime?

Part Number: TMS320F280039C


Dear Champs,

I am asking this for our customer.

How does the user read stack pointer during runtime?

They want to know the maximum stack usage to optimize their memory usage.

Note that they are aware of ERAD for stack overflow detection, and they just wonder how to read stack pointer in C or in embedded assembly code.

  • Hello Wayne,

    I wasn't able to find any assembly instruction that can read the stack pointer, but the maximum stack usage is determined by the user (they configure this in the Project Properties).

  • Dear Omer,

    The user said they used to use some codes during runtime to read the stack pointer and then optimize the stack RAM size on one of our competitors by decreasing it in .cmd and Project Properties. For example, they originally set stack size as 1000, but after long testing, they find the max stack pointer is always below 500, then they can reduce it to 500 in the next build.

    After migrating from the competitor MCU onto F28003x, they wonder if they can do so as well.

    Though they may use ERAD for overflow detection, they are asking if there is a similar way on F28003x (C28x.)

    Would you please help check this again after Jan 2 when more colleagues are back to the office?

    If you do not find any method to do so, you may still let us know later.

  • Hello Wayne,

    Unfortunately there is no direct instruction in the C28x instruction set that can read the stack pointer, I looked through the entire instruction set yesterday just to make sure. On the competitor device I'm guessing that the customer used ARM, which I believe has a way to access the stack pointer directly (which is not recommended for most situations, but I understand that this is the best way for the customer).

    The only recommendation I have is that they can monitor the memory which they use for the stack pointer instead of the stack pointer itself and look for optimizing that way, or creating their own stack pointer which is modified by following the same rules as the stack pointer.

  • Dear Omer,

    The competitor here is Microchip dsPIC33 series.

    OK, I understand.

    Thank you for your information.