cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the PC register value in STM32? Help me please.

NGUYEN-VAN NHI
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions

R14 == LR

R15 == PC

calledfromwhere ; subroutine returns address from whence it came
  movs r0, lr
  bx lr
 
Usage
   bl calledfromwhere ; assembler
 
  printf("%p\n", calledfromwhere() ); // C

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

View solution in original post

7 REPLIES 7
S.Ma
Principal

In debug mode, place a breakpoint or stop the code, and view the disassembly window which will show you which address the PC value is. Or view the SFR core registers.... why do you need this?

NGUYEN-VAN NHI
Associate III

I want to read PC value to use it for program and not for observation purpose. Is there any way sir?

Explain better what it is you're attempting to do.

I​n assembler you can move the value to other registers or do math directly with the PC. You could perhaps create a subroutine which moves LR to R0 and see where it was called from.

P​erhaps learn MCU registers, instructions and assembler?

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

Yes, I have some programs running on flash, I want to save some values from register r0 to r15 and the value of register pc, so that I can go back and continue doing my old work.

R14 == LR

R15 == PC

calledfromwhere ; subroutine returns address from whence it came
  movs r0, lr
  bx lr
 
Usage
   bl calledfromwhere ; assembler
 
  printf("%p\n", calledfromwhere() ); // C

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

I will try it, thank you very much.

Pavel A.
Evangelist III

GCC has intrinsic function __builtin_return_address() exactly for this