Reading PC runtime

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading PC runtime

479 Views
vinayhunsur
Contributor I

Hi,

My setup involves Kinetis KV3x family micro and GCC compiler. What is the best mechanism to access the value of PC during runtime for logging purposes (& also meeting compliance to some software standards) ? There are references to few inline assembly codes however they don't seem to be reliable. Are there any other ways to achieve this ?

Labels (1)
Tags (2)
0 Kudos
6 Replies

82 Views
bobpaddock
Senior Contributor III

Erich and Rong thank you for your answers, that was vinayhunsur actual question that you answered.  Hopefully he sees them. My question was to vinayhunsur's "meeting compliance to some software standards". What I want to know is what are the software standards (UL1998, DO-178D etc?) that require this? Such standards are a personal interest of mine. http://www.softwaresafety.net Erich, I have used your poor man's trace in the past.  Thank You for all that you document. Freescale parts of today would be useless without such examples. Sad how bad the docs have become from the Motorola days.

0 Kudos

82 Views
BlackNight
NXP Employee
NXP Employee

Hi Bob (and Xiangjun),

sorry for mixing up replies ("too many threads" could be my excuse).

About the software standards: with my experience, pretty much everything for safety critical systems or for good software quality requires some metrics (tested lines of code, code and test coverage, performance analysis and regression testing). I would say that should be commone sense today anyway.

As for the bad docs: If you could be more specific, I believe then someone else could jump in or at least take the feedback?

Thanks,

Erich

0 Kudos

82 Views
BlackNight
NXP Employee
NXP Employee

Hi Bob,

as you are using GNU/gcc, you have several options :-).

One way I would do it is to use

void __cyg_profile_func_enter(void *this_fn, void *call_site);

void __cyg_profile_func_exit(void *this_fn, void *call_site);

See Poor Man’s Trace: Free-of-Charge Function Entry/Exit Trace with GNU Tools | MCU on Eclipse

I'm reading and storing the program counter that way.

Another way would be to use the

__gnu_mcount_nc:

with enabled profiling. You can add there your assembly code to store the PC in your custom format if needed.

See Code Coverage for Embedded Target with Eclipse, gcc and gcov | MCU on Eclipse

Yet another way if you have either a Segger J-Link or a FRDM board with OpenSDA (and the Segger J-Link firmware on it) is to use the Segger Realtime Transfer and the Segger System Viewer. See Segger SystemView: Realtime Analysis and Visualization for FreeRTOS | MCU on Eclipse  and McuOnEclipse Components: 22-Nov-2015 Release | MCU on Eclipse. There you can instrument and measure individual pieces of code, see Data Logger with tinyK20 Board | MCU on Eclipse.

I hope this gives some ideas,

Erich

0 Kudos

82 Views
bobpaddock
Senior Contributor III

I'm curious as to what standard(s)?

0 Kudos

82 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Bob,

If you want to assign a register value to a variable or return a register value from a subroutine, it is dependent on compiler, you have to refer to the calling convention in  corresponding doc of compiler.

BR

Xiangjun Rong

0 Kudos

82 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Vinayhunsur,

  __asm("MOV R0,PC");

BR

Xiangjun Rong

0 Kudos