To set hardware tracepoints in the source code and collect trace data on the Kinetis Cortex M4 project:
- In the CodeWarrior Projects view, select the Sources folder of your project.
- Double-click the source file, for example, main.c to display its contents in the editor area. Replace the source code of the main.c file with the source code shown below.
Listing: Source code for trace collection
#include <stdio.h>
volatile int a;
void func() {
a=0;
}
int main()
{
int i;
func();
a=0;
a=1;
a=2;
a=3;
a=4;
if (a==4) a=3;
if (a==3) a=1;
if (a==1) a=4;
if (a==4) a=5;
func();
return 0;
}
- Save and build the project.
- Open the Debug Configurations dialog box, and select your project in the tree structure.
- Click the Trace and Profile tab, and check the Enable Trace and Profile checkbox.
- Click Apply to save the settings, and close the Debug Configurations dialog box.
- In the editor area, select the statement: if (a==4) a=3;.
- Right-click the marker bar, select the Toggle Trace Start Point > Hardware Trace Point option from the context menu. The same option is also used to remove the start trigger from the marker bar.
Figure 1. Setting Hardware Start Tracepoint From Source Code 
The start trigger icon appears on the marker bar in green color.
- In the editor area, select the statement: if (a==4) a=5;.
- Right-click the marker bar, and select the Toggle Trace Stop Point > Hardware Trace Point option from the context menu.
The stop trigger icon appears on the marker bar in red color. The same option is also
used to remove the stop trigger from the marker bar.
Figure 2. Hardware Start and Stop Tracepoints set in Source Code 
- Debug your application.
The application halts at the beginning of the
main() function.
- Click Resume to resume the program execution.
- Wait for some time to let the application terminate.
The
Software Analysis
view appears.
- Expand the project name and click the Trace hyperlink.
The
Trace Data
viewer appears as shown in the following two figures.
Figure 3. Trace Results After Setting Hardware Tracepoints in Source Code - Start Address 
These figures display the data file generated by the application in which the data has been collected after setting start and stop hardware tracepoints in the source code. In this data file, the
Description
field shows that trace starts collecting from the address, where you set start tracepoint, and trace collection stops before the address where you set stop tracepoint.
Figure 4. Trace Results After Setting Hardware Tracepoints in Source Code - Stop Address 
Note: Similarly, you can set hardware tracepoints from the Disassembly view. The only difference is that tracepoints are set when the program is in debug mode. After setting the tracepoints, you click Resume and collect trace data.