Intro to Code Composer Studio (CCS)

CCS is a software integrated development environment (IDE) for building and debugging programs for the DSK (Dsp Starter Kit), i.e. the dsp board. The software is used for three phases in the overall DSP system design process:

1)  Coding and building: writing code using the editor, creating a ‘project’, and compiling and linking.

2)  Debugging: syntax checking, probe points, break points

3)  Analysis: statistics, benchmarking, real-time debugging

We will go through some elements of all three phases during this lab.

This lab is to get you familiar with the software, to give you a ‘feel’ of where things are located. You are NOT expected to understand what you are doing. The ‘what is …’ questions will be answered during the course of the semester.

The content of this lab is as follows:

I. CREATING PROJECTS

Create a ‘Project’

Create a Source File

Create a Command File

Add Files to a Project

Create the Executable File

II. DEBUGGING & ANALYSIS

Run the Program

View Memory

Graphical Display of Data

Check a Variable During Program Execution

Benchmarking

Resets

During the course of this exercise, you may need to reset the board. There are several ways to do this at different levels:

- Debug> Reset CPU

- Close CCS. Start Button of Windows > Programs > Texas Instruments > Code Composer Studio DSK Tools > Hardware Resets > Reset

- Close CCS. Unplug the board and turn it back on. Wait for the LED lights to quit flashing before trying to use the board/open CCS again.

I.  CREATING PROJECTS

An executable file is created from:

.c, .asm, .sa – source files

.cmd – command file

.h – header file

.lib – library files

To manage these files for a given project, we first create a ‘project’.

Create a ‘Project’

Choose Project > View.

Type in a Project Name and a location.

The type should be .out and the target 67xx.

Hit Finish

Your project.pjt should be in the Project View window.

Create a Source File

Choose File > New > Source File

An Editor window comes up.

Type in the following assembly code which declares 10 values:

.sect “.mydata”

.short 0

.short 7

.short 10

.short 7

.short 0

.short -7

.short -10

.short -7

.short 0

.short 7

Choose File > Save

Find your project folder, call the file initmem, and choose type .asm.

Hit Save.

Let’s create another source file, a C program. This program will do nothing at the beginning, but we can develop it later on. Do as you did above, but this time for a C file which you should save as main.c. The C code is:

#include <stdio.h>

void main()

{

printf(“Begin\n”);

printf(“End\n”);

}

Create a Command File

Often times you can use an existing .cmd file. But let’s put our data in a certain part of memory so that we can access it.

Locate the Lab1.cmd file on the computer.

Choose File > Load and open the file.

After the line: .cio > IRAM,

type in: .mydata > SDRAM

This will put the data from your initmem file in a part of memory starting at 0x80000000.

Choose File > Save As. Save it in your project folder as Lab1.cmd

Although the files you have created are in your project folder, they have not been put in the folders which will be used for assembling and linking. We have to add these files to the project for this purpose.

Add Files to a Project

Project > Add Files to Project

Go to your project folder and open the initmem.asm file. This is now found under the Source folder in the Project View window.

Do the same thing for the main.c and Lab1.cmd files.

We also must add the run-time support library for the board since we have a C program. This file is located at c:\ti\c6000\cgtools\lib\rts6701.lib. This file should appear under the Libraries folder in the Project View window.

Create the Executable File, lab1.out:

Before we compile, assemble, and link, there are a number of options we can choose to determine the amount of optimization done. There are four levels (Opt Level) of optimization: 0, 1, 2, and 3. The lowest level is 0. However, sometimes, debugging can not be done when we use optimization. So we will start out using no optimization to get things working.

Project > Options

Compiler, Basic – Check that Target Version: 671x and Opt Level: None

Linker, Basic – You can change the name of the executable file which will be produced.

Project > Build compiles, assembles, and links all of the files in the project and produce the executable file lab1.out.

A window at the bottom shows if there are errors.

Project > Rebuild can be used when you have made a change to only a few files and now wish to compile, assemble, and link with the changed files.

There are shortcut buttons on the window to do Project Build and Rebuild. FIND them. They will be useful in the future.

You should have gotten a lot of errors upon building. Scroll up until you reach the first red line with ERROR! in it. Double click on the line. The file initmem.asm opens at the line where the error occurred. Assembly code required that all of the lines in this file NOT start in the first column. So enter a space at the beginning of each line in the file and then save the file.

Since we didn’t change every file in the project, we can do a Project > Rebuild (you can also use the shortcut button).

II. DEBUGGING & ANALYSIS

Run the Program

Now we can load the program into the DSP memory and execute the program.

File > Load Program and open the Lab1.out program which is in the Debug folder of your Lab1 project folder.

Debug > Run to run the program or use the shortcut button on the left. Find this button! It will be useful in the future.

Begin and End should appear in the bottom Stdout window.

View Memory:

Let’s see if the values of our initmem file are in the memory location we established in the .cmd file.

View > Memory

Type in 0x80000000 in memory location.

Format: 16bit Signed Int

A Memory window appears with the memory addresses and their contents.

## Write out on a piece of paper the memory locations for your data.

Why do you think there are two values per memory location?

Graphical Display of Data

We can graph the data which is in memory on the board:

View > Graph > Time/Frequency

Start Address: 0x80000000

Acquisition Buffer Size: 10

Display Data Size: 10

DSP Data Type: 16-bit signed integer

A graph should appear on the screen with a plot of your data.

## On a piece of paper, write down the value of the x-axis for the -10 data point.

**************************************

Before we look at additional debugging and analysis features, let’s modify our main.c program. We will assign a pointer to the beginning of our data in memory. In this way, we can bring data into our c program and print the data out.

Double-click on main.c in the project window.

Change the program so that it looks like the following:

#include <stdio.h>

void main()

{

int i;

short *point;

point= (short *) 0x80000000;

printf(“Begin\n”);

for (i=0;i<10;i++)

{

printf(“[%d] %d\n”,i, point[i]);

}

printf(“End\n”);

}

Save it, Rebuild (shortcut button on the top or Debug > Rebuild) , and Load it into the DSP memory.

Run it.

Now we are ready to do some more analysis.

**************************************

Check a Variable During Program Execution

We use ‘breakpoints’ and ‘watch’ windows to watch variables while a program runs.

We will look at the values of the variable pointer in main.c before and after the pointer assignment as well as the value of variable i.

File > Reload to reload the program (we loaded and ran it in the step before).

Double-click on main.c in the Project View window.

Put cursor on the line: point = (short *) 0x80000000

Set a breakpoint at this point by hitting the shortcut button (a hand) or right click and choose Toggle Breakpoint.

If you get a message, and CCS moves the breakpoint, that is okay. But click on Stdout window in order to see the output results.

Repeat this with the line: printf("[%d] %d\n",i, point[i]);

Highlight the variable point in the line: point = (short*) … using the mouse.

Right click and select Add to Watch Window. A watch window opens which shows the variable point.

Highlight the variable i in the line: printf(“[%d] … with the mouse.

Right click and select Add to Watch Window. This variable is now added to the window.

Hit the shortcut button for Run or Debug > Run.

The program stops at the breakpoint and the watch window shows the value of point before the pointer is set. Now let’s see what it is after being set. Hit the shortcut button ‘step over a line’ or Debug > Step Over. This moves you through the breakpoint to the next line. The pointer is now set, and you can see the value of the pointer is 0x80000000.

## Write on a piece of paper the value of the pointer before it was set by the program.

Hit the shortcut button animate or Debug > Animate and watch the variable i as the program progresses. On the other hand, you could hit the shortcut button ‘step over the line’ over and over to see the variable i change. After using ‘animate’, you need to halt the system. You can do this with the shortcut button on the left or with Debug > Halt.

If you want to do this exercise over again, go to Debug > Restart, Run, Step Over, etc.

Remove the breakpoints before continuing by hitting the shortcut button ‘Remove All Breakpoints’.

**************************************

Let’s add a subroutine to our C program which will sum the values. Then we will look at how much time it takes to run the subroutine.

Double-click on main.c in the project window and make the needed changes so that the following C program results (make sure the breakpoints are removed).

#include <stdio.h>

void main()

{

int i, ret;

short *point;

point= (short *) 0x80000000;

printf("Begin\n");

for (i=0;i<10;i++)

{

printf("[%d] %d\n",i, point[i]);

}

ret = ret_sum(point,10);

printf(“Sum = %d\n”,ret);

printf("End\n");

}

int ret_sum(const short* array, int N)

{

int count, sum;

sum=0;

for(count=0; count<N; count++)

sum += array[count];

return(sum);

}

Go through all the steps necessary to run the program.

## Write on another piece of paper what you got as the sum.

**************************************

Benchmarking

Now we will benchmark or time the subroutine. In other words, we will see how long it takes for ret_sum() to run.

Reload the program and then choose Profiler > Start New Session and give your session a title, Lab1. A profile window comes up in the bottom.

Double-click on main.c in the project window. Put your cursor on the line: int ret_sum(const short* array, int N).

Several shortcut buttons are on the left side of the Profile Window. Hit the Create Profile Area button. Make sure the type is Function. The line number corresponds to the beginning of the function since this is where you placed the cursor. Hit OK.

Now expand Lab1.out under the Files window pane. The function ret_sum should be there.

Hit the Run shortcut button. The value for the Incl. Total is the number of clock cycles needed to run the function ret_sum.

## Record this number on a piece of paper.

If you want to redo this exercise, highlight ret_sum in the Files window pane, right click, and select Clear Selected. Then hit Debug > Restart. Now Run with the shortcut button.

Now we will look at the effects of optimizing on the amount of time required to run the function.

Project > Build Options. Choose Compiler and Basic. Choose Opt Level –o0. OK.

Shortcut button Rebuild All or Project > Rebuild All.

File > Load Program Lab1.out.

Highlight ret_sum in the Files pane, right click, and Clear Selected.

Hit shortcut button Run or Debug > Run.

## Record the number of clock cycles which were required for ret_sum with this level of optimization.

Repeat the above for the other levels of optimization o1, o2, and o3.