Intro to Code Composer Studio _CCS_ by maclaren1


									            Intro to Code Composer Studio (CCS)                           Run the Program
                                                                          View Memory
CCS is a software integrated development environment (IDE) for            Graphical Display of Data
building and debugging programs for the DSK (Dsp Starter Kit), i.e.       Check a Variable During Program Execution
the dsp board. The software is used for three phases in the overall       Benchmarking
DSP system design process:
   1) Coding and building: writing code using the editor, creating        During the course of this exercise, you may need to reset the board.
      a „project‟, and compiling and linking.                             There are several ways to do this at different levels:
   2) Debugging: syntax checking, probe points, break points              - Debug> Reset CPU
   3) Analysis: statistics, benchmarking, real-time debugging             - Close CCS. Start Button of Windows > Programs > Texas
                                                                          Instruments > Code Composer Studio DSK Tools > Hardware
We will go through some elements of all three phases during this          Resets > Reset
lab.                                                                      - 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
This lab is to get you familiar with the software, to give you a „feel‟   again.
of where things are located. You are NOT expected to understand
what you are doing. The „what is …‟ questions will be answered            I.     CREATING PROJECTS
during the course of the semester.
                                                                          An executable file is created from:
The content of this lab is as follows:                                    .c, .asm, .sa – source files
                                                                          .cmd – command file
I. CREATING PROJECTS                                                      .h – header file
                                                                          .lib – library files
Create a ‘Project’
Create a Source File                                                      To manage these files for a given project, we first create a „project‟.
Create a Command File
Add Files to a Project                                                    Create a ‘Project’
Create the Executable File
                                                                          Choose Project > View.
II. DEBUGGING & ANALYSIS                                                  Type in a Project Name and a location.
                                                                          The type should be .out and the target 67xx.
Hit Finish                                                               void main()
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:            Create a Command File

.sect “.mydata”                                                          Often times you can use an existing .cmd file. But let‟s put our data
.short 0                                                                 in a certain part of memory so that we can access it.
.short 7
.short 10                                                                Locate the Lab1.cmd file on the computer.
.short 7                                                                 Choose File > Load and open the file.
.short 0                                                                 After the line: .cio > IRAM,
.short -7                                                                type in: .mydata > SDRAM
.short -10                                                               This will put the data from your initmem file in a part of memory
.short -7                                                                starting at 0x80000000.
.short 0                                                                 Choose File > Save As. Save it in your project folder as Lab1.cmd
.short 7
                                                                         Although the files you have created are in your project folder, they
Choose File > Save                                                       have not been put in the folders which will be used for assembling
Find your project folder, call the file initmem, and choose type .asm.   and linking. We have to add these files to the project for this
Hit Save.                                                                purpose.
                                                                         Add Files to a Project
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      Project > Add Files to Project
did above, but this time for a C file which you should save as           Go to your project folder and open the initmem.asm file. This is
main.c. The C code is:                                                   now found under the Source folder in the Project View window.
                                                                         Do the same thing for the main.c and Lab1.cmd files.
#include <stdio.h>                                                       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.                             Since we didn‟t change every file in the project, we can do a Project
                                                                         > Rebuild (you can also use the shortcut button).
Create the Executable File, lab1.out:
                                                                         II.     DEBUGGING & ANALYSIS
Before we compile, assemble, and link, there are a number of
options we can choose to determine the amount of optimization            Run the Program
done. There are four levels (Opt Level) of optimization: 0, 1, 2, and
3. The lowest level is 0. However, sometimes, debugging can not          Now we can load the program into the DSP memory and execute the
be done when we use optimization. So we will start out using no          program.
optimization to get things working.                                      File > Load Program and open the Lab1.out program which is in the
Project > Options                                                        Debug folder of your Lab1 project folder.
Compiler, Basic – Check that Target Version: 671x and Opt Level:
None                                                                     Debug > Run to run the program or use the shortcut button on the
Linker, Basic – You can change the name of the executable file           left. Find this button! It will be useful in the future.
which will be produced.
                                                                         Begin and End should appear in the bottom Stdout window.
Project > Build compiles, assembles, and links all of the files in the
project and produce the executable file lab1.out.                        View Memory:
A window at the bottom shows if there are errors.
Project > Rebuild can be used when you have made a change to only        Let‟s see if the values of our initmem file are in the memory location
a few files and now wish to compile, assemble, and link with the         we established in the .cmd file.
changed files.
There are shortcut buttons on the window to do Project Build and         View > Memory
Rebuild. FIND them. They will be useful in the future.                   Type in 0x80000000 in memory location.
                                                                         Format: 16bit Signed Int
You should have gotten a lot of errors upon building. Scroll up until    A Memory window appears with the memory addresses and their
you reach the first red line with ERROR! in it. Double click on the      contents.
line. The file initmem.asm opens at the line where the error             ## Write out on a piece of paper the memory locations for your
occurred. Assembly code required that all of the lines in this file      data.
NOT start in the first column. So enter a space at the beginning of         Why do you think there are two values per memory location?
each line in the file and then save the file.
Graphical Display of Data                                                  {
                                                                              printf(“[%d] %d\n”,i, point[i]);
We can graph the data which is in memory on the board:                     }
View > Graph > Time/Frequency                                          }
Start Address: 0x80000000
Acquisition Buffer Size: 10                                            Save it, Rebuild (shortcut button on the top or Debug > Rebuild) ,
Display Data Size: 10                                                  and Load it into the DSP memory.
DSP Data Type: 16-bit signed integer                                   Run it.
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 -   Now we are ready to do some more analysis.
10 data point.
                                                                       Check a Variable During Program Execution
Before we look at additional debugging and analysis features, let‟s
modify our main.c program. We will assign a pointer to the             We use „breakpoints‟ and „watch‟ windows to watch variables while
beginning of our data in memory. In this way, we can bring data        a program runs.
into our c program and print the data out.
                                                                       We will look at the values of the variable pointer in main.c before
Double-click on main.c in the project window.                          and after the pointer assignment as well as the value of variable i.
Change the program so that it looks like the following:
                                                                       File > Reload to reload the program (we loaded and ran it in the step
#include <stdio.h>                                                     before).

void main()                                                            Double-click on main.c in the Project View window.
{                                                                      Put cursor on the line: point = (short *) 0x80000000
   int i;                                                              Set a breakpoint at this point by hitting the shortcut button (a hand)
   short *point;                                                       or right click and choose Toggle Breakpoint.
   point= (short *) 0x80000000;                                        If you get a message, and CCS moves the breakpoint, that is okay.
   printf(“Begin\n”);                                                  But click on Stdout window in order to see the output results.
   for (i=0;i<10;i++)                                                  Repeat this with the line: printf("[%d] %d\n",i, point[i]);
Highlight the variable point in the line: point = (short*) … using the   Let‟s add a subroutine to our C program which will sum the values.
mouse.                                                                   Then we will look at how much time it takes to run the subroutine.
Right click and select Add to Watch Window. A watch window
opens which shows the variable point.                                    Double-click on main.c in the project window and make the needed
Highlight the variable i in the line: printf(“[%d] … with the mouse.     changes so that the following C program results (make sure the
Right click and select Add to Watch Window. This variable is now         breakpoints are removed).
added to the window.
                                                                         #include <stdio.h>
Hit the shortcut button for Run or Debug > Run.
The program stops at the breakpoint and the watch window shows           void main()
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 >      int i, ret;
Step Over. This moves you through the breakpoint to the next line.          short *point;
The pointer is now set, and you can see the value of the pointer is         point= (short *) 0x80000000;
0x80000000.                                                                 printf("Begin\n");
## Write on a piece of paper the value of the pointer before it was         for (i=0;i<10;i++)
set by the program.                                                         {
Hit the shortcut button animate or Debug > Animate and watch the                printf("[%d] %d\n",i, point[i]);
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       ret = ret_sum(point,10);
variable i change. After using „animate‟, you need to halt the              printf(“Sum = %d\n”,ret);
system. You can do this with the shortcut button on the left or with        printf("End\n");
Debug > Halt.                                                            }

If you want to do this exercise over again, go to Debug > Restart,       int ret_sum(const short* array, int N)
Run, Step Over, etc.                                                     {
                                                                             int count, sum;
Remove the breakpoints before continuing by hitting the shortcut             sum=0;
button „Remove All Breakpoints‟.                                             for(count=0; count<N; count++)
                                                                                 sum += array[count];
**************************************                                       return(sum);
Go through all the steps necessary to run the program.                 Now we will look at the effects of optimizing on the amount of time
## Write on another piece of paper what you got as the sum.            required to run the function.

**************************************                                 Project > Build Options. Choose Compiler and Basic. Choose Opt
                                                                       Level –o0. OK.
Benchmarking                                                           Shortcut button Rebuild All or Project > Rebuild All.
                                                                       File > Load Program Lab1.out.
Now we will benchmark or time the subroutine. In other words, we       Highlight ret_sum in the Files pane, right click, and Clear Selected.
will see how long it takes for ret_sum() to run.                       Hit shortcut button Run or Debug > Run.
                                                                       ## Record the number of clock cycles which were required for
Reload the program and then choose Profiler > Start New Session        ret_sum with this level of optimization.
and give your session a title, Lab1. A profile window comes up in
the bottom.                                                            Repeat the above for the other levels of optimization o1, o2, and o3.

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.

To top