Query related to reading current stack poniter DS32K142

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Query related to reading current stack poniter DS32K142

556 Views
sardalkar
Contributor I

We have query related to reading current stack pointer with STS instruction.  Below is macro defined to read current SP, but it is giving compilation error (identifier STS is undefined)

 

#define GET_STACKPOINTER(x) _asm(STS x) Is the STS instruction supports for cortex M4 (DS32k142)?

 

Please let us know if you have any alternative solution for getting current stack pointer with direct RAM accessible instruction.

Labels (1)
0 Kudos
1 Reply

445 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Sandip Ardalkar,

I'm not aware of the macro that you are trying to use. However, I made an example to read the stack pointer on run time with a different approach. The following function returns the value of the stack pointer.

void *GetSP(void)
{
#ifdef __GNUC__
  void *sp;
  __asm__ __volatile__ ("mov %0, sp" : "=r"(sp));
  return sp;
#else
  #warning "only for GCC"
  return NULL;
#endif
}‍‍‍‍‍‍‍‍‍‍‍

To call the function I did the following:

  /* Getting SP */
  void* (*vfunc)(void);
  vfunc = GetSP;
  void* StackPointer = vfunc();
  uint32_t sp = (uint32_t)StackPointer;‍‍‍‍‍

At the end the variable sp will have the value of the stack pointer.


Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos