You are on page 1of 16

EE 472 Lab 1 (Individual) Introduction to C and the Lab Environment

University of Washington - Department of Electrical Engineering

Introduction:

This lab has two main purposes. The first is to introduce the C language, explore some of the important aspects of the language including pointers. The second is to introduce the Atmel AT91SAM7SExxx implementation of the ARM7 microcomputer (Make Controller), the Eclipse integrated C / Assembler development environment, and the world of embedded applications. Like a typical embedded system, we have a hardware piece and a software piece. This quarter, our major focus will be on the software piece. The best way to become familiar with any new piece of hardware is to take a tour of its features; the same holds true for learning a new programming language. This is the approach that we will take. We will take the same approach as we move to the microprocessor and associated development environment. For the processor, well begin with the data sheet and discover some of the key features of this device. This is exactly how we will do it in future when we start to work with a new microprocessor for our company or in our graduate research. Then, once again, we will begin with a working application, learn how to build a project, compile it, download it, and run it on the target platform. We will then make some simple modifications to the program and verify that the modified programs work as expected.
Prerequisites:

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

We will be continuing our work and learning process with a new microprocessor and development environment this quarter. Sometimes it can be frustrating when the software or the microprocessor doesnt behave the way we want it to, or when, unfortunately, it behaves the way that we have told it to, or when we cant immediately find the answer to our questions and problems. Sometimes your instructor or TA will have the answers and sometimes they wont. As we said in the opening, bear in mind that were learning the environment and tools too this platform and development environment are complex and are new to all of us. If we all work together to identify and solve problems as they occur, everyone benefits and we help to build for the next classes. The answers are there somewhere. Lets all work to find them. Regardless of the specific platform/environment used, embedded systems development requires at least the following: 1. A target platform on which to develop the application. 2. A mechanism for programming the target platform.

Target platform is a term used loosely in industry to mean the actual piece of hardware that performs the computation and/or control the place where our application will ultimately run. A target platform can be a simple a single chip (i.e. a PIC), or as complicated as a feature-rich single board computer (build around a multicore high performance processor and possibly several programmable logic devices). Despite the differences in physical characteristics, the target platforms purpose is the same: to execute the software written by the developer. Here, and for the typical microprocessor based application, the software will be the C language. On a programmable logic device, it may be a mixture of C and Verilog, for example. The term to program here has two meanings. The first is the more traditional sense and simply means writing software to control a given piece of hardware (in this case the target platform see above). In the embedded world, programming the target also means storing the executable into memory on the target. As the characteristics of the target platform can vary greatly, so too can the mechanism used to program the target platform. Some development environments allow one to develop directly on the target platform (much like developing code on a PC), while others require that code be developed on another host computer and then transferred to the target platform. We call this transfer downloading to the target platform. Apart from the actual technique(s) used, every embedded system has to provide a mechanism for programming it. One of the more difficult concepts to learn in C is the notion of pointers. Once you begin to see what they are, youll find that theyre actually rather straightforward. In reality, pointers are nothing more complicated than a variable type whose value is interpreted as the address of something in memory. This is exactly the same as interpreting a collection of bits (theyre just bits) as an integer, a character, a floating point number, some interesting picture that you downloaded from one of those special websites on the internet, or all the data on your hard drive as a really big integer. There is a very good explanation of pointers with accompanying drawings in your text. Take the time to read through this material.
Laboratory Environment

This laboratory environment is equipped with Make Controller and Application Board (see class material link on class webpage for more information on Make). As its name implies, the Make system is a feature-rich single board computer equipped with an ARM 7 microprocessor. The ARM 7 is a RISC processor that runs at up to 55 MHz. As a point of interest, we note that all CPU hertzes are not created equal. Based upon its architecture and the way that the machine operated, an ARM 7 running at 55 MHz has the potential of being more powerful than a Pentium running at the same speed. The ARM 7 architecture supports two instruction sets: a 32-bit implementation (called ARM) in support of high performance embedded designs and a 16-bit implementation (called Thumb) that supports a reduced memory footprint for smaller embedded applications. The ARM 7 utilizes a three-stage pipeline architecture: instruction fetch, decode, and execute. Well talk about what all these mean in class.

Interestingly, the ARM family of microprocessors are actually a design (piece of intellectual property) licensed by ARM to a variety of different companies to build. This company grew out of a small company, Acorn Computers, in the UK From Wikipedia Acorn Computers was a British computer company established in Cambridge, England, in 1978. The company produced a number of computers which were especially popular in the UK. These included the Acorn Electron, the BBC Micro and the Acorn Archimedes. Acorn's BBC MicroComputer dominated the UK educational computer market during the 1980s and early 1990s, drawing many comparisons with Apple in the U.S. Though the company was broken up into several independent operations in 1998, its legacy includes the development of RISC personal computers. A number of Acorn's former subsidiaries live on today notably ARM Holdings who are globally dominant in the mobile phone and PDA microprocessor market. Acorn is sometimes known as "the British Apple". The version of the processor on the Make Controller is the Atmel AT91SAM7X256. Some other features include: Memory o 32 KB SRAM o 256 KB Flash memory Memory Controller s o SDRAM o SRAM o Error Corrected Code Controller Interrupt Controller and programmable number of external interrupt inputs I/O Communication o Three Parallel Input / Output (PIO) Controllers o 2 USART serial ports o SPI and CAN interfaces o USB port o Ethernet interface JTAG Boundary Scan interface Debug Support Internal Peripherals o 3 16-bit timers o 4 Channel PWM Controller o 8 Channels 10-bit A/D o Real-time Timer o 8 Digital outputs 4 with high current drive

o 8 Digital inputs

Figure 1: Make Controller

Figure 2: Pinouts

In this class, we will use many of these hardware features as we design and develop the various laboratory projects; the details regarding each of the components will be given as needed. To program the Make Controller target platform, a host PC is required. Using the Eclipse C Development Environment, code can be developed on a standard PC and then downloaded into the target platform over a USB serial connection.

Figure 3: Schematic of the EE 472 Accessory Board.

Objectives

Introduce the C language, C programs, and the PC development environment: the basic C/C++ preprocessor, program structure, multiple file programs, pointers, passing and returning variables by value and by reference to and from subroutines, designing, compiling, and debugging on a host PC. Introduce the laboratory environment: the embedded development environment, the target platform, host PC, equipment, etc. Learn a bit about the Atmel version of the ARM 7 Processor.
Learning the C Language & Working with the Development Environment and Target Platform

Well be working with the Eclipse IDE and the Make (ARM 7) Application Board. First Steps Our first step is to install the tools that well need and some sample software onto the machine on which we are working. You can go directly to the Make website http://www.makingthings.com/resources/downloads then Firmware 1.6.2 source code. Once you have the package downloaded, unzip it and extract all of the files to your machine. The following discussion assumes that we are working in the directory.\ firmware-v1.6.2\projects. The prefix of the path is wherever you put the files on your machine. Note, also, I am working on a PC rather than under Linux. You can place this directory on your H: drive if you wish. You are strongly encouraged to work in this directory (.\ firmware-v1.6.2\projects ).

Configuring the Project We now begin by opening Eclipse and setting our current workspace. You can open the Workspace Launcher window from File|Switch Workspace|Other if it didnt popup automatically. Using the H: drive is highly recommended. Note: The directory names along the workspacepathname cannot contain any spaces. Also, Figure 4 shows an older version, but you should be using the newer version discussed above. Select OK The first splash screen appears. Select Workbench

Figure 4

Figure 5

Select File New C Project

Figure 6

Select Makefile project WinARM Yagarto Give your project a name Well use: LEDDriverTinyLab1 Note: The project name cannot contain any spaces this is why there are no spaces in the name that we have chosen. See we learned earlier when we had a directory and file name with spaces in them. It didnt work. The compiler couldnt find anything. This is where the frustration in software development comes in.

Figure 7

Select Finish

Your environment should now appear as in figure 8.

Figure 8

Next, the application needs the source code and tools to build our application. Normally, we would write these ourselves. However, for this application, we are working with existing code. Thus, we must import them into our project. Download LedDriverTiny.zip from the lab1 page on the class website. Feel free to download it and unzip it onto your desktop or any other place. We wont be building this downloaded copy, so it doesnt have to be on the H:\ drive. Next, we need to import the downloaded project into the new project we just created.

Select the following in the Project Explorer pane in the Eclipse IDE: LedDriverTinyLab1 Using the right mouse button to open the selector menu

Figure 9

Select Import On the menu that pops up Select General File System

10

Figure 10

Select Next In the window that pops up, browse to the directory where you stored the folder LedDriverTiny. Select the folder LedDriverTiny and select Open Select the checkbox next to LedDriverTiny. This will, in turn, select all of the files in the right hand window.

11

Figure 11

Select Finish to copy over all files Open the directory structure under the heading LEDDriverTinyLab1 and your display should look something like that in figure 12.

12

Figure 12

Select main.c and double click to open the file in the display window. Go to the Project menu and select Build All or simply type ctrl + B. This will compile your program. There should be no errors and your display should look like this

Figure 13

13

You have just built your first ARM 7 application Wahoo that should go on your resume. Downloading to the Target Before we can download our application, we need more tools. Thus, its back to the Make download website. This time, get select and download the file: mchelper 2.5.1 (http://www.makingthings.com/files/mchelper/2.5.0/mchelper-v2.5.1-setup.zip). By now, you know the routine.download the file, unzip it, extract, and install everything. Make certain that your Make board is connected to your PC through one of the USB ports. Turn power ON to the board Reset the board thats the red button on the system. Cycle power on the board dont even think it. I didnt make up these rules. Im just following them. The McHelper display should now appear something like:

Figure 15

Browse to /LEDDriverTinyLab1/output directory. Select tiny.bin Highlight Samba Board Select upload

14

Your display on McHelper should look like

Figure 16

as the file tiny.bin is being downloaded to your ARM 7. It should start executing automatically. You should now see LED0 on the Make Application board and the LED on the Make Controller board flashing. Your just successfully completed your first ARM 7 project.
Building Your Own Applications

Now that you have successfully run an existing application on the target platform, this next exercise we will make a series of changes to the program to gain practice in some of the techniques that we will have to use in our more complex applications. Application 1 Modify the program LEDDriverTinyLab1.c to flash leds LED-0..LED-3 at approximately a one-second rate. Application 2 Modify the program LEDDriverTinyLab1.c to turn each of the leds: LED-0..LED-3 ON then each of the leds OFF in sequential order (and then circle back) at approximately a one-second rate.

15

Application 3 Modify the program LEDDriverTinyLab1.c to flash LED-0 and LED-2 at a one-second rate and LED1 and LED-3 at approximately a two second rate. Implement the delay as a function with the following prototype:
void delay(int aDelay);

Application 4 Write an application that uses the LCD (call it LCDDriverLab1.c). This new application should implement the following display function:
void display(char* text, int length, int* delayInSeconds);

This function takes in a pointer to the first element of a character array, which represents the text, the length of the text (i.e., number of chars), and a pointer to a delay value. Your function should display and flash the text on the LCD using the referenced delay amount. You may use lcd_test (from the example code in the lab1 directory) as a basis for your application. You should also take a look at the lcd displays datasheet.
Deliverables

A lab report containing (Lab1 should be done individually) 1. The annotated source code for all four applications (in the appendix). 2. Because there are so few features to this lab, we dont expect a full lab report that goes into detail about the test cases, results, etc. We just want to know how you implemented the applications, problems you ran into, and any interesting insights and tricks you discovered. Create a single zip file and submit Lab1 using the turn in link provided on the webpage. Make sure to include your name in the report. Setup a time to demo your applications to the TA or instructor.

16

You might also like