Skip to main content
LThal
Associate III
January 10, 2019
Question

How to read program counter in C

  • January 10, 2019
  • 4 replies
  • 4503 views

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

This topic has been closed for replies.

4 replies

LThal
LThalAuthor
Associate III
January 10, 2019

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
January 10, 2019

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;
}

Tesla DeLorean
Guru
January 10, 2019

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
LThal
LThalAuthor
Associate III
January 10, 2019

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