cancel
Showing results for 
Search instead for 
Did you mean: 

How to read program counter in C

LThal
Associate II

Hi. I'm trying to determine which flash bank running code resides in. I'm planning on reading the program counter and use that to determine which bank I'm in. Both GCC and the Arm compiler have some variant of a __current_pc() intrinsic. I haven't been able to find anything like that in TrueStudio (or I haven't found the right include file, directory, something). Can anyone point me to either the location of this function, or another method of finding the information I need. Thanks.

Lee

5 REPLIES 5
LThal
Associate II

Thank you, Uwe. In fact, I found that same posting about 2 minutes after I posted my question and it works well.

S.Ma
Principal

Before looking at complicated macro, you can get the function start address like this:

uint32_t myfunction(uint32_t v);
 
uint32_t myfunction(uint32_t v) {
  
  uint32_t function_address = (uint32_t) myfunction;
  
  return 0;
}

LThal
Associate II

It works out to 2 lines of code, so not that complicated. But thanks for your suggestion as well.

More interesting would be where it's being called from, so MOV R0, LR; BX LR

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..