'C/C++' Project/Code Tutorial for Code Composter Studio (CCS)

Similar documents
F28069 ControlCard Lab1

F28335 ControlCard Lab1

Code Composer Studio. MSP Project Setup

Table of Figures Figure 1. High resolution PWM based DAC...2 Figure 2. Connecting the high resolution buck converter...8

System Framework Overview Guide and Instructions on How to Use the Template Projects

F28027 USB Stick Lab1_3

Lab 0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

PSIM Tutorial. How to Use SPI in F2833x Target. February Powersim Inc.

Using Code Composer Studio IDE with MSP432

Using Eclipse for Java. Using Eclipse for Java 1 / 1

As CCS starts up, a splash screen similar to one shown below will appear.

TUTORIAL Auto Code Generation for F2803X Target

TMS320F2808, TMS320F2806 and TMS320F2801 SDFlash JTAG Flash Programming Utilities

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

TUTORIAL Auto Code Generation for F2806X Target

APPENDIX A. CODE COMPOSER STUDIO (CCS) v5: A BRIEF TUTORIAL FOR THE DSK6713

TMS320F28335, 28334, Flash APIs

M16C/62P QSK QSK62P Plus Tutorial 1. Software Development Process using HEW4

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Migrating from Keil µvision for 8051 to IAR Embedded Workbench for 8051

TMS320F2810, TMS320F2811, and TMS320F2812 Flash APIs. Version 2.10

Note that FLIP is an Atmel program supplied by Crossware with Atmel s permission.

As CCS starts up, a splash screen similar to one shown below will appear.

E85 Lab 8: Assembly Language

Microcontroller basics

F2802x Firmware Development Package USER S GUIDE. F2802x-FRM-EX-UG-210. Copyright 2012 Texas Instruments Incorporated

Embedded Target for TI C6000 DSP 2.0 Release Notes

TMS320F2802x SDFlash JTAG Flash Programming Utilities

Table of Figures Figure 1. Two pole two zero controller module...2

TMS320x2803x Piccolo Control Law Accelerator (CLA) Reference Guide

TMS320F2810, TMS320F2811 and TMS320F2812 SDFlash JTAG Flash Programming Utilities

Interrupt Driven Programming in MSP430 Assembly (ESCAPE) *

Lab 1: Guide for creating portable projects in C2000

Topics. Interfacing chips

MEM MEM Control Applications of DSP. Lab 2. Project Creating & GPIO DSP28355 & CCSv5

SKP16C26 Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

Familiarity with data types, data structures, as well as standard program design, development, and debugging techniques.

Copyright 2015 by Stephen A. Zajac & Gregory M. Wierzba. All rights reserved..spring 2015.

PSIM Tutorial. How to Use SCI for Real-Time Monitoring in F2833x Target. February Powersim Inc.

Application Note. Title: Incorporating HMT050CC-C as a Digital Scale Display by: A.S. Date:

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet Example Application...

Exercise: PWM Generation using the N2HET

Lab 4 Interrupts ReadMeFirst

1 Introduction to Computers and Computer Terminology Programs Memory Processor Data Sheet... 4

BHFlashBurn v2.0. User Guide. BHFlashBurn-UG-02 April 2008

ADSP-BF707 EZ-Board Support Package v1.0.1 Release Notes

Why embedded systems?

EE 354 Fall 2015 Lecture 1 Architecture and Introduction

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

Chapter 09. Programming in Assembly

Embedded programming, AVR intro

One 32-bit counter that can be free running or generate periodic interrupts

Floating-Point Unit. Introduction. Agenda

Emulating an asynchronous serial interface (USART) via software routines

8051 Microcontroller memory Organization and its Applications

April 4, 2001: Debugging Your C24x DSP Design Using Code Composer Studio Real-Time Monitor

AT89S8252 Development Board V1.0. Manual

HOW TO USE CODE::BLOCKS IDE FOR COMPUTER PROGRAMMING LABORATORY SESSIONS

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

ECE2049 Embedded Computing in Engineering Design. Lab #0 Introduction to the MSP430F5529 Launchpad-based Lab Board and Code Composer Studio

HandsOn Technology -- HT-MC-02 MODEL: HT-MC-02

3 TUTORIAL. In This Chapter. Figure 1-0. Table 1-0. Listing 1-0.

EMBEDDED SYSTEMS: Jonathan W. Valvano INTRODUCTION TO THE MSP432 MICROCONTROLLER. Volume 1 First Edition June 2015

Section Objective: Acquaint with specifications of Launchpad Acquaint with location of switches, LEDs, power-on switch, powering the board.

Ch. 3: The C in C++ - Continued -

Resource 2 Embedded computer and development environment

revolution GETTING STARTED Appendix H - Frequently Asked Questions (FAQ). Section 1 92

Newbie s Guide to AVR Interrupts

Mechatronics Laboratory Assignment 2 Serial Communication DSP Time-Keeping, Visual Basic, LCD Screens, and Wireless Networks

Getting Started in C and Assembly Code With the TMS320LF240x DSP

The Riverside Robotic Society June 2016 ESP8266

Summer 2003 Lecture 14 07/02/03

Lab 1: I/O, timers, interrupts on the ez430-rf2500

ECE QNX Real-time Lab

FAE Summit Interfacing the ADS8361 to the MSP430F449 Low Power Micro Controller

USB Debug Adapter. Power USB DEBUG ADAPTER. Silicon Laboratories. Stop. Run. Figure 1. Hardware Setup using a USB Debug Adapter

DSP Platforms Lab (AD-SHARC) Session 05

DAVE 3 Hands on / Quick Start Tutorial. Presentation Tutorial Start 1 v1.1: Creating a simple Project using PWM and Count Apps

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

University of Massachusetts Amherst Computer Systems Lab 1 (ECE 354) LAB 1 Reference Manual

Intel x86 instruction set architecture

Moses Jones Application Note ECE 480 Design Team 7 Programming Altimeters. Using MSP 430 Launch Pad 11/8/2013

TMS320F2810, TMS320F2811 and TMS320F2812 SDFlash JTAG Flash Programming Utilities

Today s Menu. >Use the Internal Register(s) >Use the Program Memory Space >Use the Stack >Use global memory

Processor Expert Software Microcontroller Driver Suite. Device Initialization User Guide

Laboratory Exercise 3 Comparative Analysis of Hardware and Emulation Forms of Signed 32-Bit Multiplication

C Language Programming

Tools Basics. Getting Started with Renesas Development Tools R8C/3LX Family

Building an Embedded Processor System on Xilinx NEXYS3 FPGA and Profiling an Application: A Tutorial

Mechatronics Laboratory Assignment #1 Programming a Digital Signal Processor and the TI OMAPL138 DSP/ARM

ADuC814 GetStarted Guide a tutorial guide for use with the ADuC814 Quickstart Development System CONTENTS:

C Language Programming through the ADC and the MSP430 (ESCAPE)

ECEN 4613/5613 Embedded System Design Week #6 Spring 2018 Homework #6

NIOS CPU Based Embedded Computer System on Programmable Chip

Special Topics for Embedded Programming

Microcontroller and Embedded Systems:

YOU WILL NOT BE ALLOWED INTO YOUR LAB SECTION WITHOUT THE REQUIRED PRE-LAB.

Programming in the MAXQ environment

WS_CCESSH5-OUT-v1.01.doc Page 1 of 7

C281x C/C++ Header Files and Peripheral Examples Quick Start

Transcription:

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) 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

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.

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.

Here is a short list of useful registers that can be used with the auto-complete feature: GpioCtrlRegs GpioDataRegs SysCtrlRegs AdcRegs SpiaRegs SpibRegs CpuTimer1Regs PieCtrlRegs PieVectTable In order to find additional functions, look within the linked header files (see image to the right), and scroll down to the very bottom of the desired.h file to find all the supported register names for auto-complete. Pointers and Memory Addresses: In order to write to your LCD screen, you will need to be able to write directly to the output latch that the screen is connected to. Since the port/latch is located at 0x4000 in memory, that will be the address that you need to write to. In assembly this was done by MOV AR0,#0x4000 and MOV *AR0,AH (or where ever your value is stored). However, in C/C++ code the procedure is a little bit different and requires the use of a pointer. The pointer will need to be set so that it points to the 0x4000 memory location. Once this is done, then you can write data values to that location as you normally would. The code to implement the described pointer is provided for you below. int latch, *val; latch = 0x4000; val = (int *)latch; This can be used for any address location that needs to be written to, whether it is the port/latch at 0x4000 or any other external parts (such as memory) which requires a read or write at a specific address.

Interrupt Service Routines: In order to use Interrupt Service Routines (ISR's) in C/C++ code there are a few steps you will need to take. Included in the list of header files that were loaded earlier is a file called "DSP2833x_DefaultIsr.c". This file contains the declarations for all ISR's that are available to our processor. For this example, the INT13 ISR for CPU Timer 1 will be used as an example. There are two different ways to modify the DefaultIsr.c file for our purposes. The first method involves finding the ISR you want in the DefaultIsr.c file, and then copying and pasting it into the code of your project. Then you will need to comment out the copied code in DefaultIsr.c in order to avoid the conflict of having two identically named functions. From there you can just write your own code straight into the ISR you copied. This is convenient because you do not have to constantly flip between files when you are editing your code. Note that you should remove the the two lines of code for the asm and for commands as they are not needed when the ISR is being used. The alternate method is to directly modify the ISR in the DefaultIsr.c file. If you do so make sure to either comment out or clear the two lines of code for asm and for. LCD Screen Setup: During the one of the labs, you will need to add an LCD screen to your board for use in the labs. In order to write to the LCD, you will need to use the output latch that has been installed onto your board. Data will be written to LCD screen at address 0x4000, and you will need to use the pointer described above in "Pointers and Memory Addresses" to do this. However, there is a lot more detail to the screen than just writing to a spot in memory. The details will be discussed in class and there is a datasheet which specifies a lot of important information, but this document will briefly cover an efficient way to write algorithms for the LCD screen in C/C++ code. Make sure you read about the LCD screen beforehand, as the remaining information will not make a lot of sense otherwise. The LCD screen will be likely be used in 4-bit mode, and if so it gets even more complicated, but in general the process to write to the screen can be broken up into 3 functions: Control, Data, and Write. To write to the control register requires different signal levels than writing to the data register, but the actual writing procedure is identical. Therefore, making a write function that is independent of which register is being written too would make the code more efficient. With this in mind, the best way to write the code is to make Control and Data functions, each of which call the Write function after all the signal levels have been set correctly. Then call the appropriate function, with the input being the desired data to display, in your code in order to write to one or the other.

The Write function itself will need to create a synthetic/artificial clock signal on the LCD pin 'EN'. You will need to toggle the EN bit within the write function by changing that single bit of the output data from '1' to '0 to '1'. This creates the needed clock edge to latch in the data signal, and this is the main reason that creating a separate write function makes the code more efficient. Note that in order to add the proper signal levels for bits such as EN and RS, use the OR logical function to place the desired high levels in, or the AND function to turn a high into a low. If you do use the LCD in 4-bit mode, then take the input byte and use shift operators and AND operators to split the 8 bits into two 4-bit 'nibbles'. The nibbles then will need the signal levels added into them, and then the write function will need to be called two times. When in 4-bit mode, always send out the higher nibble of the data out first. Inline Assembly: There may be times you will need to use assembly commands in the middle of your C/C++ programs in order to utilize the higher speed at which assembly runs. The procedure for including assembly code into a C/C++ code file is known as 'inline assembly'. The example below shows how to use it with a simple NOP. The command asm() is used, and the quotation marks are important. It is only possible to put a single command per asm() used. In order to execute a 5 line assembly command, 5 asm() commands would have to be used. asm("nop");