301x Filetype PDF File size 0.56 MB Source: www.add.ece.ufl.edu
'C/C++'
Project/Code
Tutorial
for
Code
Composter
Studio
(CCS)
University
of
Florida,
Electrical
&
Computer
Eng.
March,
2014
Authors:
Dr.
K.
Gugel
&
R.
Jacobi
Introduction
The purpose of this document is to explain how to create a 'C' or 'C++' code program in Code Composer Studio
for Version 5.1 of the software. Students should be proficient in writing assembly code for the TMS320F28335
DSP and now can use C/C++ coding for labs and projects. First, you will need to get the file ' sprc530.zip' from
the class website or Texas Instruments website.
Procedure:
1. Download sprc530.zip from TI.com or our class’ reference web page.
2. Extract the zip file.
3. Run "
setup_DSP2833x_v131.exe" - Choosing the default installation options is recommended.
4. Create a new directory for your C/C++ code project, and copy the linker command file
"KG_RAM_Link1.cmd" into this directory.
5. Start Code Composer Studio.
6. Create a new CCS project. File > New > CCS Project
a. Type in a name for your project, and make sure the output type is 'Executable'
b. You can change the desired location for your project if you wish.
c. Under "Device", make sure that the Family is set to C2000. The Variant should be set to Generic
C28xx Device.
d. Under "Advanced Settings", make sure the linker file has been properly selected where it says
Linker command file. If it does not, browse and find the "KG_RAM_Link1.cmd" file to link it
to the project correctly.
e. Under "Project templates and examples" make sure you select an Empty Project, not the
Assembly-only Project that was used before.
f. Finish Project creation now.
'C/C++'
Project/Code
Tutorial
for
Code
Composter
Studio
(CCS)
University
of
Florida,
Electrical
&
Computer
Eng.
March,
2014
Authors:
Dr.
K.
Gugel
&
R.
Jacobi
7. In the project browser window, right-‐click the project name, select the Add Files… option and link the
following files from the directory created by the setup_DSP2833x_v131.exe program
(C:\tidcs\c28\DSP2833x\v131\ if default location was selected):
a. /DSP2833x_headers/cmd/DSP2833x_Headers_nonBIOS.cmd
b. /DSP2833x_headers/source/DSP2833x_GlobalVariableDefs.c
c. /DSP2833x_common/source/DSP2833x_ADC_cal.asm
d. /DSP2833x_common/source/DSP2833x_CodeStartBranch.asm
e. /DSP2833x_common/source/DSP2833x_DefaultIsr.c
f. /DSP2833x_common/source/DSP2833x_Mcbsp.c
g. /DSP2833x_common/source/DSP2833x_PieCtrl.c
h. /DSP2833x_common/source/DSP2833x_PieVect.c
i. /DSP2833x_common/source/DSP2833x_Spi.c
j. /DSP2833x_common/source/DSP2833x_SysCtrl.c
k. /DSP2833x_common/source/DSP2833x_usDelay.asm
Each time you will be prompted by the program about how the file should be imported:
Select the options as shown in the image above to link the files properly.
Note: You can select and link multiple files at the same time by holding down 'Ctrl' while
selecting each individual file.
8. Next to go Project > Properties.
a. Go to Build > C2000 Compiler > Include Options.
b. Next to “Add dir to #include search path (-‐-‐include_path, -‐I)” select Add (left most button) and
add the following directories:
i. /tidcs/c28/DSP2833x/v131/DSP2833x_headers/include
ii. /tidcs/c28/DSP2833x/v131/DSP2833x_common/include
'C/C++'
Project/Code
Tutorial
for
Code
Composter
Studio
(CCS)
University
of
Florida,
Electrical
&
Computer
Eng.
March,
2014
Authors:
Dr.
K.
Gugel
&
R.
Jacobi
9. Create a new Target Configuration File (same as what you have done for your previous assembly
projects) for your lab DSP board, or copy it from a previous project and add it to this new project.
Now your Code Composer Studio is properly set-up for C/C++ code. The remainder of this tutorial will now
cover the basics of writing C/C++ code in CCS. Topics that are covered will be: Adding includes, useful starting
code, using the auto-complete feature of CCS (which runs off the Eclipse system), how to use pointers for
memory addresses, how to use interrupt service routines, and tips on setting up the LCD screen in an efficient
manner.
Code Basics:
Note: For the remainder of this tutorial, all of the code examples will be for C++ code.
New Code File:
In order to make a new file for your C/C++ code do the following:
1. File > New > Source File
2. Type in the desired file name, such as "Example.cpp". Note that for a C file, you need to end the file
name with .c, and for a C++ file, you need to end the file name with .cpp.
3. Select the correct language template in the Template drop down menu.
Includes:
Every C/C++ file should use the following include:
• #include "DSP28X_Project.h"
Beyond this, there are a number of useful includes you may want to use at certain times. Only use includes you
actually need though, as each one takes up space on the DSP's memory.
• #include "math.h" - Used for more advanced math functions such as sqrt and floor.
• #include "FPU.h" - This is a floating point header which you will need to download and link later in the
semester for certain labs.
Starting code:
If you are writing in C or C++ you will need to declare the "main" function correctly. As mentioned above, this
tutorial will give examples for C++ code only.
int
main
{
EALLOW;
//
Allows
for
I/O
pins
to
be
used
for
inputs
and
outputs.
SysCtrlRegs.WDCR
=
0x0068;
//
Turns
off
the
Watchdog
timer.
}
As you can see, the code to remove the Watchdog timer has been reduced to a single line now, as opposed to
Assembly code which required writing to 0x7029 with 0x0068 over 3 lines of code instead. The EALLOW
function works the same as it did in Assembly.
'C/C++'
Project/Code
Tutorial
for
Code
Composter
Studio
(CCS)
University
of
Florida,
Electrical
&
Computer
Eng.
March,
2014
Authors:
Dr.
K.
Gugel
&
R.
Jacobi
Since you will be using this processor for DSP application, having it run at a high clock speed will be very useful
as the faster clock speeds will allow the processor to run more calculations per second and increase the
functionality of the device. In order to increase the clock speed use the following lines of code:
SysCtrlRegs.PLLSTS.bit.DIVSEL
=
0;
SysCtrlRegs.PLLCR.bit.DIV
=
0xA;
SysCtrlRegs.PLLSTS.bit.DIVSEL
=
2;
With this code, the CPU's clock speed, SYSCLKOUT, will be bumped up to 75 MHz. In order to understand how
this code works, look at Pages 58-61 of the DSP's manual (tms320f28335.pdf). Note that some functions may use
the Low-Speed Clock (LSPCLK) instead. If that is the case, it will be up to you to determine how to adjust the
LSPCLK.
Auto-Complete Feature:
One of the best features of Code Composer Studio is that runs of the Eclipse architecture. As a result of this, there
is very handy auto-complete feature which will simply writing C/C++ code especially at the beginning when you
are still learning syntax. This allows you to modify many of the key registers including the GPIO Control and
Data Registers, and the set-up and initialization registers for functions such as the SPI and the ADC.
In order to use this feature, you need to know the name of the register you are trying to modify. For this example,
GpioCtrlRegs will be used. In order to trigger the auto-complete, type in "GpioCtrlRegs" and then type a single
"." afterwards. If the set-up covered above was done correctly, you will see a menu similar to the one shown
below.
Note: If the menu does not appear, it is likely that you either did not properly add all the include files, or that you
did not correctly link the header files.
With this, it is possible to easily set individual bits as needed. It is also possible to set entire strings of bits in one
line as well, by using .all instead of .bit. When setting more than a single bit you will need to use the datasheets to
determine how wide the register so you know how many bits to place. The format of the string of bits is up to you,
but using hexadecimal is recommended.
no reviews yet
Please Login to review.