Docstoc

Instruction trace and function trace

Document Sample
Instruction trace and function trace Powered By Docstoc
					Example 7: Instruction trace and function trace
A basic capability of Instruction Trace is to display the sequence of all executed instructions —
optionally with embedded source code — that have been collected to the J-Trace buffer. These
instructions are shown in the ETM Trace window of C-SPY. Another window, Function Trace, shows a
subset of trace data corresponding to calls to and returns from C functions. Developers can then inspect
the program flow up to a specific state and use trace data to locate the origin of the problem.

Due to the limited size of the trace buffer, it is not possible to record a very long sequence of instructions
in real time. The comparators in DWT can be used to generate trigger events for ETM, controlling the
start and stop of data collection. The position and conditions of the trigger points are set by dedicated
breakpoints in C-SPY: Trace Start, Trace Stop, or Trace Filter. These triggers can be based on code or
data.

Requirements: Cortex-M3/M4 board that supports ETM trace; J-Trace for Cortex-M3; IAR Embedded
Workbench for ARM, V5.50.5 or later.

Step 7.1
The same as Step 1.1 and 1.2. Note that J-Trace should be connected to the target board through the
19-pin flat trace cable.

Step 7.2
On some devices, the ETM trace port pins are multiplexed with other on-chip peripherals and might not
be enabled by default. The trace port must be explicitly set up in the source code or by a C-SPY macro
file. Please note that these pins cannot be used for other purposes in the application.

Step 7.3
Download your application into the target by starting the C-SPY debugger.

Open the ETM Trace Settings dialog box from the J-Link menu, where:
   •    Trace Port Width should be 4 Bits;
   •    Trace Port Mode should be “Normal, half-rate clocking”;
   •    Trace Buffer Size can be up to 0x00200000.
                                                                                                     Page 2




Step 7.4
Here is an example of the code to be traced. The two assignments to the variable testPoint are used as
locations to set trigger points:

volatile int testPoint;
……
testPoint = 0;
TheCodeToBeTraced( ); // e.g. prinf( );
testPoint = 1;


Step 7.5
Trigger points can be based on code addresses. When the application reaches the specified code
address, Instruction Trace will start or stop.

    •   In the Source window, right-click the line “testPoint = 0;” and choose Toggle Breakpoint (Trace
        Start) from the context menu.
    •   To stop the execution after trace, right-click the source line “testPoint = 1;” and choose Toggle
        Breakpoint (Code) from the context menu. The created breakpoints can be viewed and edited
        in the Breakpoints window, available from the View menu.




Step 7.6
Open the ETM Trace and the ETM Function Trace windows from the J-Link menu. Click the
Enable/Disable button on toolbar of the ETM Trace window to turn on ETM. Start executing the
application and pass through the piece of code. Instruction Trace will be started from the Trace Start
breakpoint. When the execution stops at the code breakpoint thereafter, the collected code sequence
will be displayed at the level of instructions and C functions respectively in these two windows.
                                                                                                     Page 3




Step 7.7
Trigger points can also be based on data accesses. When the specified variable or address range is
accessed, Instruction Trace will start or stop.

    •   In the Source window, right-click the variable name testPoint and choose Set Trace Start
        Breakpoint for ‘testPoint’.
    •   To stop the execution after trace, right-click the source line “testPoint = 1;” and choose Toggle
        Breakpoint (Code).




    •   Right-click the Trace Start breakpoint in the Breakpoints window and choose Edit from the
        context menu. Set options for Access Type, Size and Match Data for the access to testPoint
        that will start the ETM trace. Then repeat Step 7.6 to trace the same code by the data trigger.
                                                                 Page 4




Main article: Using CoreSight Trace Techniques on Cortex-M3/M4

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:12/3/2011
language:English
pages:4