Sie sind auf Seite 1von 10

EE 472 Lab 1 Introducing the Lab Environment

Introduction:

This project has two main purposes. The first is to introduce the C language, explore some of the important aspects of the language including pointers and multiple file programs, then practice simple debugging. The second is to introduce the Texas Instruments Stellaris EKI!"S#$%& implementation of the '(! Cortex-!" )*! microcomputer, the I'( S+stems Embedded ,or-bench integrated C . 'ssembler de)elopment en)ironment, and the world of embedded applications. ,ow, so, when is the final project due/ i-e a t+pical embedded s+stem, we ha)e a hardware piece and a software piece. This term, our major focus will be on the software piece. 0ou are strongl+ encouraged to read the entire project before tr+ing to start designing or exploring1.then read it again in case +ou missed something1sometimes, one more time. The best wa+ to become familiar with an+ new piece of hardware is to ta-e a tour of its features2 the same holds true for learning a new piece of software or programming language. This is the approach that we will ta-e. ,e will ta-e our first steps with the C language b+ starting with a wor-ing C program. ,e will ma-e se)eral modifications to the program then compile and run our )ersions. 3ext, we will wor- with se)eral programs that compile and appear to wor- properl+ and +et contain se)eral common errors. 4sing our debugger in the I'( I5E, we will tr+ to identif+ and correct those errors. Then, we will build our project, compile it, download it, and run it on the target platform. ,e will ta-e the same approach as we mo)e on to more complex projects in future. 's we explore the processor, we6ll begin with the data sheet and disco)er some of the -e+ features of this de)ice. This is exactl+ how we will do it in future when we start to wor- with a new microprocessor for our compan+ or in our graduate research.1.then, on the second da+1
Prerequisites:

7amiliarit+ with data t+pes, data structures, as well as standard program design, de)elopment, and debugging techni8ues.
Background

7or us, this is a new microprocessor and de)elopment en)ironment. earning new components and tools is exciting and challenging. This is one of the fun parts of engineering. 't the same time, sometimes it can be frustrating when the hardware or the software doesn6t beha)e the wa+ we want it to, or when, unfortunatel+, it beha)es exactl+ the wa+ that we ha)e told it to, or when we can6t immediatel+ find the answer to our 8uestions and problems. 't this stage in learning engineering and about the engineering process, pla+ing with the to+s often seems to be the most exciting part1the documentation, formal design, and so on, is, well, often seen as rather boring. Why do I have to go through all thiswhy cant I just go to the Internet and find something like the design and make a few modifications and be done? - 9 of 9: -

In the real-world, the documentation and formal design are absolutel+ critical parts of all phases of the engineering de)elopment process. 5oing it and doing it right can mean the difference between success or failure of a project, the malfunction of the s+stem following deli)er+ to the customer, or the possible loss of life while it is being used. It6s also )er+ important to recogni;e and to remember that the answers to most interesting real-world engineering problems originate in our brains, disco)ered as we use our imaginations and -nowledge to creati)el+ appl+ the underl+ing theor+2 the+ are reached through our persistent hard wor- and diligence. The solutions to challenging problems are not sitting, read+, and waiting for us on the Internet. The <i-ings didn6t disco)er 3orth 'merica b+ searching some ancient )ersion of the Internet1the+ too- ris-s1the+ explored and challenged. ,e didn6t find the solution for ma-ing the first successful airplane flight, to putting someone on the moon, to ma-ing the first soft landing on !ars, or to programming the first microprocessors, or the disco)er+ of the =iggs boson on the Internet1we won6t find the answers to man+ of toda+6s problems or the labs this 8uarter there either. ,e challenge +ou to explore, to thin-, and to ma-e those disco)eries. Sometimes +our instructor or T's will ha)e the answers and sometimes we won6t. 's we said in the opening, bear in mind that we6re >starting to wor- with? learning the en)ironment and tools too. This platform and de)elopment en)ironment are complex and are new to all of us >but we6re learning?. If we all wor- together, to identif+ and sol)e problems as the+ occur, e)er+one benefits and we help to build for the next classes. The answers are there somewhere. et6s all wor- to find them. (egardless of the specific platform.en)ironment used, embedded s+stems de)elopment re8uires at least the following@ 9. 'n understanding of the problem that we are tr+ing to sol)e. &. ' target platform on which to de)elop the application. ". ' mechanism for programming the target platform. Target platform is a term used loosel+ in industr+ to mean the actual piece of hardware that performs the computation and.or control A the place where our application >the software? will ultimatel+ reside and run. ' target platform can be as simple as a single chip microprocessor >i.e. a BIC or an 'rduino?, or as complicated as a feature-rich single board computer >build around a multicore high performance processor, se)eral special purpose processors, and possibl+ se)eral programmable logic de)ices?. 5espite the differences in ph+sical characteristics, the target platform6s purpose is the same@ to execute the software written b+ the de)eloper. =ere, and for the t+pical microprocessor based application, the software will be written in the C language. Cn man+ occasions, the CDD language ma+ be used2 for what are called hard realtime s+stems, Ea)a is rarel+ used. Cn a programmable logic de)ice li-e an 7BF', it ma+ be a mixture of C and <erilog, for example. The term to program here has two meanings. The first is the more traditional embedded sense and simpl+ means writing software to control a gi)en piece of hardware >in this case the target platform and an+ peripheral de)ices that ma+ be connected to it A see abo)e?. In the embedded world, programming the target also means storing the executable into memor+ on the target. 's the characteristics of the target platform can )ar+ greatl+, so too can the mechanism used to program the target platform. - & of 9: -

Some de)elopment en)ironments allow one to de)elop directl+ on the target platform >much li-e de)eloping code on a BC?, while others re8uire that code be de)eloped on another host computer and then transferred to the target platform. ,e call this transfer downloading to the target platform. 'part from the actual techni8ue>s? used, e)er+ embedded s+stem has to pro)ide a mechanism for programming it. Cne of the rumored to be more difficult concepts to learn in C is the notion of pointers. Cnce +ou begin to see what the+ are and how the+ wor-, +ou6ll find that the+6re actuall+ rather straightforward. In realit+, pointers are nothing more complicated than an identifier or )ariable t+pe whose value is interpreted as the address of something in memor+. This is exactl+ the same as interpreting a collection of bits >the+6re just bits? as an integer, a character, a floating point number, some interesting picture that +ou downloaded from one of those special websites on the internet >don6t download stuff here using GitTorrent A the+ ha)e no sense of humor and will shut the uni)ersit+6s networ- down?, or all the data on +our hard dri)e as a reall+ reall+ big integer. ,eird, huh/ There is a )er+ good explanation of pointers with accompan+ing drawings in +our text. Cnce again, ta-e the time to read through this material.
Develo ment Environment

The de)elopment en)ironment will be the Stellaris s+stem. This s+stem is a feature-rich single board computer e8uipped with a Cortex-!" microprocessor which is a follow-on from the '(! *. 's a point of interest, among the '(!6s earl+ ancestors was the GGC !icrocomputer from 'corn Computers, td. The official Acorn I!" machine project was started in Cctober 9$#". 7rom ,i-ipedia1 Acorn "omputers was a #ritish computer company established in "ambridge$ %ngland$ in &'()* The company produced a number of computers which were especially popular in the +,* These included the Acorn %lectron$ the ##" -icro and the Acorn Archimedes* Acorn.s ##" -icro computer dominated the +, educational computer market during the &')/s and early &''/s$ drawing many comparisons with Apple in the +*!* 'lthough the compan+ was bro-en up into se)eral independent operations in 9$$#, its legac+ includes the de)elopment of (ISC personal computers. ' number of 'cornHs former subsidiaries li)e on toda+ A notabl+ '(! =oldings who are globall+ dominant in the mobile phone and B5' microprocessor mar-et. 'corn is sometimes -nown as Ithe Gritish 'ppleI. Interestingl+, the '(! famil+ of microprocessors are actuall+ a design >piece of intellectual propert+? licensed b+ '(! to a )ariet+ of different companies to build. 5oes an+one in industr+ reall+ use these things/ ,ell, let6s see. G+ &::J, about $# percent of the more than one billion mobile phones sold each +ear used at least one '(! processor. Two +ears ago, '(! processors accounted for approximatel+ $:K of all embedded "&-bit (ISC processors. The Cortex-!" is a (ISC A (educed Instruction Set Computer A processor that runs at up to J: !=; +et, we obser)e that all CB4 hert;es are not created e8ual. Gased upon its

- " of 9: -

architecture and the wa+ that the machine operated, a Cortex-!" running at J: !=; has the potential of being more powerful than a Bentium running at the same speed. The '(! * architecture supports two instruction sets@ a "&-bit implementation >called '(!? in support of high performance embedded designs and a 9%-bit implementation >called Thumb A upgraded to Thumb & in the Cortex-!"? that supports a reduced memor+ footprint for smaller embedded applications. i-e the '(! *, the Cortex-!" utili;es a three-stage pipeline architecture@ instruction fetch, decode, and execute. ,e6ll tal- about what all these mean in class. The )ersion of the processor on the Stellaris is the Texas Instruments '(! Cortex-!" )*!. Some other features include@ !emor+ o %L KG S('! o &J% KG 7lash memor+ Interrupt Controller and programmable number of external interrupt inputs =ardware-di)ision and single-c+cle-multiplication I.C Communication o Se)en Feneral Burpose I.C bloc-s A J-L& programmable I.C pins o & 4'(Ts with Ir5' support o I&C, SSI and C'3 interfaces o 4SG port o Ethernet interface ET'F Goundar+ Scan interface 5ebug Support Internal Beripherals o L "&-bit timers o (eal time timer o % Channel B,! Controller o L Channels 9:-bit '.5 o 'nalog Comparator In this class, we will use man+ of these hardware features as we design and de)elop the )arious design projects2 the details regarding each of the components will be gi)en as needed. To program the Stellaris Cortex-!" target platform, a host BC is re8uired. 4sing the IA !ystems %mbedded Workbench, code can be de)eloped on a standard BC, cross compiled for the Cortex-!", and then downloaded into the target platform o)er a 4SG serial connection.

- L of 9: -

Pro!ect "b!ectives

Introduce the C language, C programs, and the BC de)elopment en)ironment@ the basic C.CDD preprocessor, program structure, multiple file programs, pointers, passing and returning )ariables b+ )alue and b+ reference to and from subroutines, designing, compiling, and debugging on the target platform. Introduce the wor-ing en)ironment@ the embedded de)elopment en)ironment, the target platform, host BC, e8uipment, etc. earn a bit about the Texas Instruments )ersion of the Cortex-!" Brocessor.

Learning the Environment and #ools $ #he %irst &te s

's our first step, we will first wor- with the I'( Embedded ,or-bench tools to build and run an existing simple program on the EKI- !"S#$%& chip. The source code for se)eral of the programs we will be using is in the same director+ as the project assignment. Working with the Tools
Building and Running a Program

9. Starting with step " of the Stellaris Muic-start A I'( Tools document, Compile A select -ake or ebuild All from the 0roject tab 5ownload to the target board A select 1ownload and 1ebug from the 0roject tab. &. ,hen the code has been downloaded to the target board, )erif+ that the debugging halts with the cursor sitting on the start of the main routine.

- J of 9: -

". To run the program, select function -e+ 7J or 23 from the 1ebug tab. <erif+ that +ou ha)e displa+ed 4ello on the C E5.
Building Your Own Program

9. Starting with the section@ "reating a 5ew 0roject in of the Stellaris Muic-start A I'( Tools document, complete all of the specified steps to create a new project. &. ,hen +ou ha)e completed creating +our new project, it should appear as the currentl+ acti)e program in the Workspace pane >left hand window? of the I'( I5E. ". Expand the project to show its contents. 0ou should ha)e@ dri)erlib.a main.c rit99&#x$%xL.c startupNewarm.c L. Select main.c, open the right mouse menu, and select emove to delete the file from the project.

J. Cn +our BC, find the director+ and project that +ou6)e just created. 5elete the file main.c from that project. %. 7ind the file project9a-&:9".c and cop+ it to +our project director+ on +our BC and rename it main.c. L. In the I5E, right clic- on the project and select 'dd O 'dd 7iles1

- % of 9: -

J. 'dd the new main.c to +our project.

%. 'nnotate each line of the program to identif+ its purpose in the program and what it does >these reall+ are different?. *. Compile +our program and download it to the target board. There should be no errors A if there are, then bad cop+ing. #. Select 1ownload and 1ebug from the 0roject tab $. To run the program, select function -e+ 7J or 23 from the 1ebug tab. The program should count in decimal according to the following pattern. 3ote that the following is actuall+ &: iterations through the program and the program6s output will appear on onl+ two lines on the C E51.at time t:, the )alue : is displa+ed1at time t9, the )alues : 9 are displa+ed and so forth. The )alue of i is@ : :9 :9& :9&" :9&"L :9&"LJ :9&"LJ% :9&"LJ%* :9&"LJ%*# :9&"LJ%*#$ 9&"LJ%*#$ &"LJ%*#$ "LJ%*#$ LJ%*#$ J%*#$ %*#$ *#$ #$ $

t:@ t9@ t&@ t"@ tL@ tJ@ t%@ t*@ t#@ t$@ t9:@ t99@ t9& t9"@ t9L@ t9J@ t9%@ t9*@ t9#@ t9$@ t&: :

- * of 9: -

9:. !odif+ the program to parameteri;e the two delay67 function calls in the two for loops so that the+ will support different user specified dela+s rather than the single hard coded )alue as the+ are now. ,here will those )alues ha)e to be specified/ =ow do we get them into the program/ 5on6t ma-e it complicated. 99. !odif+ the program so that each of the two respecti)e for loops is replaced b+ the following functions.
void f1Data(unsigned long delay1) void f!"lear(unsigned long delay!)

9&. !odif+ the program so that parameter, dela+, is passed into the two functions in part L abo)e b+ reference rather than b+ )alue. 9". !odif+ the program so that the two functions in part 9& abo)e are replaced b+ a single function. The function should be able to be called with the character to be displa+ed and the )alue of the dela+. 9L. !odif+ the program so that the function +ou wrote in part 9" is in a separate file. 0our program will now be composed of two files.
Working With the De#ugger

earning to use a debugger is an in)aluable s-ill to de)elop if one is planning to do an+ serious software de)elopment wor-. ,ahoo, we actuall+ ha)e a debugger this 8uarter. The need to de)elop strong debugging s-ills is independent of whether one de)elops embedded or des-top applications. 'gain from ,i-ipedia1 The terms IbugI and IdebuggingI are both popularl+ attributed to 'dmiral Frace =opper in the 9$L:s. ,hile she was wor-ing on a !ar- II Computer at =ar)ard 4ni)ersit+, her associates disco)ered a moth stuc- in a rela+ and thereb+ impeding operation, whereupon she remar-ed that the+ were IdebuggingI the s+stem. =owe)er the term IbugI in the meaning of technical error dates bac- at least to 9#*# and Thomas Edison. 7urther IdebuggingI seems to ha)e been used as a term in aeronautics before entering the world of computers. The I'( de)elopment en)ironment pro)ides some rather effecti)e tools that help +ou to debug +our code running on the !"S#$%&. 0ou ha)e alread+ wor-ed with some useful features.abilities@ setting and clearing brea-points running to cursor single-stepping through or o)er code inspecting the contents of local.global )ariables inspecting and change the )alues of )ariables during runtime loo-ing at how +our high-le)el C code is translated to assembl+

- # of 9: -

7or each of the abo)e items, there are man+ wa+s to perform the desired action. ' brief summar+ on how to do each one is as follows@
Breakpoints A To set a brea-point, mo)e the cursor to the left hand window

border next to the desired line of code and left-clic- +our mouse button. 0ou can unset a brea-point b+ simpl+ repeating the process. 'lternatel+, +ou can place +our cursor on the desired line of code, then select Prun to cursor6 from either the main 1ebug or the right mouse menus. Bersonall+, I prefer to Prun to cursor6. Gear in mind that a brea-point is not the place in +our debugging process where +ou throw up +our hands and go for a beer.
Single-stepping A ,hen in the debug mode, to single-step over each instruction

in the code, press the 79: -e+. To step into a function >rather than o)er?, press the 799 -e+. 3ote that the code must be halted in the debug mode2 it cannot be single-stepped while it is running. i-e brea-points, single-stepping is not the process of slowl+ snea-ing out when +ou6)e reached a brea-point.
Local/Global Variables A To inspect local.global )ariables, select either Add

Watch or Quick Watch from the menu choices that appear. The elected )ariables and their )alues will appear in a window on the right hand side of the I5E. Explore a bit to see what the differences are. et6s now put the debugger to wor-. 9. Guild a project containing the code from the file project9b-&:9".c and rename it main.c. The program will compile and execute apparentl+ correctl+, howe)er, there is a problem with it. 4sing +our debugger, identif+ what the problem is and indicate how +ou found it with the debugger. Correct the problem and using +our debugger, pro)e that +ou ha)e, indeed, fixed the problem. &. Guild a project containing the code from the file project9c-&:9".c and rename it main.c. The program will compile, howe)er, it has a problem during execution. 4sing +our debugger, identif+ what the problem is and indicate how +ou found it with the debugger. Correct the problem and using +our debugger, pro)e that +ou ha)e, indeed, fixed the problem.
Building 'our "(n ) lications

3ow that +ou ha)e successfull+ run an existing application on the target platform, this next exercise we will ma-e a series of changes to the program to gain practice in some of the techni8ues that we will ha)e to use in our more complex applications.

- $ of 9: -

$%%li&ation 1 4sing what +ou ha)e learned from the example programs in the pre)ious exercises, write a program that will displa+ the letters@ ' G C 5 on the C E5 and flash them together at approximatel+ a one-second rate. $%%li&ation ! !odif+ the program in 'pplication 9 to print then erase the letters ' then G then C then 5 at approximatel+ a one-second rate. $%%li&ation ' !odif+ the program in 'pplication 9 to flash the letters ' and C at a one-second rate and the letters G and 5 at a two-second rate. Implement the dela+ as a function with the following protot+pe@
void delay(int aDelay)

Deliverables

' project report containing 9. The annotated source code for all applications for the Cortex-!" Brocessor. &. (epresentati)e screen shots showing the results of executing the applications on the BC screen.

- 9: of 9: -

Das könnte Ihnen auch gefallen