How can I get the PC register value in STM32? Help me please.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-17 9:45 PM
Solved! Go to Solution.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-18 6:56 AM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-17 10:49 PM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-17 11:14 PM
I want to read PC value to use it for program and not for observation purpose. Is there any way sir?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-17 11:39 PM
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?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-17 11:43 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-18 6:56 AM
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
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-18 7:00 AM
I will try it, thank you very much.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-18 1:46 PM
GCC has intrinsic function __builtin_return_address() exactly for this
