University of Florida EEL 4744 – Spring 2007 Dr. Eric M. Schwartz Electrical & Computer Engineering Casey T. Morrison, TA Page 1/3 Revision 2 April 18, 2007 Lab 8: Automatic Execution and Programming in C OBJECTIVES • To experience how easy it is to implement microprocessor concepts already learned using assembly language with a high-level language like C. • To modify the start-up behavior of the UF-6812 development board. • To put together some of the systems you have used this semester and use them to create an application- specific microprocessor-based system. MATERIALS • All parts from labs 5 and 6. PRE-LAB REQUIREMENTS • Read the ENTIRE lab handout. • Complete the GNU installation instructions outlined in the “C-Language Environment Set-up” section. • Write complete, syntax error-free programs to meet the program requirements. • Be prepared to demonstrate your programs and hardware. • Bring to lab: 1. Printout of the syntax error-free C file(s) and “memory.x” file. 2. All .c, .x, and .s19 files on a flash, CD, or floppy. 3. Answers to the pre-lab questions. YOU WILL NOT BE ALLOWED IN THE LAB WITHOUT THE PRE-LAB! COMPILER INTRODUCTION Throughout the semester, you have been writing code in Motorola assembly language and translating that code into machine code targeted for the Freescale 68HC12 microcontroller. This translation was performed by the MiniIDE assembler. While this design flow is suitable in many circumstances, i.e., writing a simple device driver or a Basic Input/Output System (BIOS), many embedded microcontroller-based systems are developed using high- level languages. When a high-level language is used in the design flow, a compiler becomes necessary to translate the source code into a lower-level language (i.e., assembly code or object code). Many of today’s microcontrollers (Texas Instruments’ MSP430 series, Atmel AVR series, etc.) are sold with development tools capable of translating high- level programming languages (C, C++, Java, etc.) into machine code targeted to their particular architecture. Depending on the application, software development may be done entirely in assembly, entirely in a higher-level language, or in a combination of the two. In this lab, we will make use of a GNU development chain to compile and assemble C-language programs for the Freescale 68HC12. C-LANGUAGE ENVIRONMENT SET-UP Follow these steps to set up a C-language software development environment: 1. Download the GNU Development chain for the Freescale 68HC12 micro-controller: • GCC 68HC12 Windows Package Release 2.2: http://m68hc11.serveftp.org/EXE/gnu-68hc1x- 2.2.exe . Use folder c:\gnu instead of the default of c:\usr. • GNU development chain website (for reference): http://www.gnu.org/software/m68hc11/m68hc11 _port.html Follow the installation instructions for installing gnu- 68hc1x-2.2. I suggest that you install this software in “C:\gnu\”; if you do not install the software here, make sure the path does not contain any spaces. 2. Download a make utility: • GNU make: http://prdownloads.sf.net/mingw/mingw32- make-3.80.0-3.exe?download . Use folder c:\gnu instead of the default of c:\mingw. I suggest that you install this in the “C:\gnu\” directory. If you do, then the file “mingw32- make.exe” should end up in the “C:\gnu\bin\” directory. Rename this file to “make.exe”. C-LANGUAGE EXAMPLE PROGRAM Follow these steps to download, compile, and execute the example program “hello.c” to make sure that your environment set-up is complete. 1. Place the files in the example archive “hello.zip” (see link on the Labs page) into the “C:\gnu\hello\” directory. 2. Right mouse click on “My Computer”, then select “Properties”, then select the “Advanced” tab. The select “Environment Variables”. Under “System variables” select for “Path” and then select “Edit”. Add the following to the end of the “Variable value:” ;C:\gnu\bin\ Select “OK”, then “OK”, then “OK” again. 3. Open a “Command Prompt” window. • One way to do this is by using the Windows shortcut. Press the “Windows Key” (often between the Ctrl and Alt keys) and R (Win-R) at the same time. The type “cmd” and hit the “Enter” key. • Alternatively, Select “Start | Programs | Accessories | Command Prompt”. 4. Change directories (cd) to where you placed the example code, “hello.c”: University of Florida EEL 4744 – Spring 2007 Dr. Eric M. Schwartz Electrical & Computer Engineering Casey T. Morrison, TA Page 2/3 Revision 2 April 18, 2007 Lab 8: Automatic Execution and Programming in C C:\...> cd c:\gnu\hello 5. Edit the “memory.x” file (using Notepad or another text editor) to describe the available program and data memory on your UF-6812 development board. The “memory.x” file provided in this example archive describes a typical memory set-up. Note that “0x” is a prefix for hexadecimal. 6. Compile, link, and assemble the example C-language program, “hello.c” into both an elf file (hello.elf) and an s19 file (hello.s19). C:\...> make hello The file elf file is a binary file in the ELF/DWARF-2 standard format. It contains 68HC12 binary code, symbols, and debugging information. This is also known as an object file. The .s19 file is known as a machine code file and can be downloaded and executed on your EEL 4744 development board. Verify that these two files were generated. 7. Run the following command to take the elf object file and convert it to a readable assembly language format: m6811-elf-objdump -d -S hello.elf > hello.lst where hello.lst is the list file containing the assembly language of the object file. This file also has the C source-code included in the file. (Without the “>”, which is know as a redirection, the output would go to the screen instead of to hello.lst.) Execute the program by itself to get a choice of possible options, i.e., “m6811-elf-objdump” Execute the program by itself to get a choice of possible options, i.e., “m6811-elf-objdump” To view the memory contents, execute: m6811-elf-objdump -s hello.elf > hello.txt 8. Compare the hello.c file to the hello.lst file with the hello.txt file. Annotate (circle and label) on printouts of these three files where a single instruction (or set of instructions) exist in the each of these files. For example “clr c0” in the hello.lst file corresponds to “_io_ports[M6812_SC0BDH]=M6812_9600_BAUD_HI;” in the hello.c file and the “7900c0” on the line labeled 0970 in the hello.txt file. Do this for three different instructions (or sets of instructions). 9. Download and execute “hello.s19” on your UF-6812 development board. You will need to “GO” at the address you have defined as the beginning of program (code) memory in your “memory.x” file. HARDWARE SET-UP If you have not already done so, download Version 2.4 of the UF Debug-4744 Monitor program to your EEPROM. This version implements a slight change to the way the board boots up. After reset, the monitor program will first read the value on Port A/D pin 7. If this pin is low (0V), then the standard monitor message and prompt interface will appear on your screen, and the monitor will await your instructions. If this pin is high (+5V), then the monitor will bypass the standard user interface, and it will direct the 68HC12 to begin executing instructions from address $8000. Set-up and test the new version of the monitor program by doing the following: 1. Connect a switch (with pull-up/pull-down resistor) to Port A/D pin 7 (this corresponds to header J4 pin 2). 2. Before powering up the board, set the switch so that it drives 0V on Port A/D pin 7. 3. Power up the board, and execute a few monitor commands to verify that the board is working. In a previous lab you added 8KB of SRAM to your system memory map starting at address $4000. For this lab, you will need move your SRAM so that it begins at address $8000. 1. Program your CPLD with a new schematic (or VHDL) that places your 8KB of SRAM at address $8000. Verify that your board still boots. If the board does not boot, verify that your CPLD SRAM equation is correct and that your file contains the equations for all of the other components (EEPROM, input port, output port, and the SRAM). 2. Once you verify your SRAM is working at $8000, download a test program (e.g., blinking an LED, displaying a string on the LCD, etc.) to address $8000. Flip the switch that controls the monitor boot mode so that it drives +5V on Port A/D pin 7 (this is “bypass mode”). Verify that the monitor bypasses the standard monitor message and prompt interface and immediately begins executing the test program at address $8000. 3. Flip the switch that controls the monitor boot mode back to driving 0V (this is “normal mode”). PROGRAMMING IN C Now you are ready to write a program in C, compile and assemble it for your 68HC12, and execute it immediately after reset. Write a program that will play the Windows XP startup theme on the your piezo speaker immediately after reset and then display the text “Welcome to’s EEL4744 board” on the LCD screen. A modified version of the Windows XP startup theme is University of Florida EEL 4744 – Spring 2007 Dr. Eric M. Schwartz Electrical & Computer Engineering Casey T. Morrison, TA Page 3/3 Revision 2 April 18, 2007 Lab 8: Automatic Execution and Programming in C described in Table 1. (Feel free to replace the Windows XP startup theme with another recognizable tune.) Note # Note name Frequency Duration 1 C7 2093.00 500 ms 2 G6 1567.98 250 ms 3 F6 1396.91 500 ms 4 C7 2093.00 250 ms 5 G6 1567.98 500 ms Table 1. Note sequence and corresponding frequencies and durations for the Windows XP startup theme. The simplest way to begin writing this program is to copy the entire “hello” directory into a new directory, say “lab8”. In this directory, rename “hello.c” to “lab8.c”, and modify the code accordingly. Be sure to update your “memory.x” file to reflect the fact that your SRAM was moved from address $4000 to address $8000. It is important to draw your attention to the array named “_io_ports” that is defined in “hello.c”. All registers and memory-mapped I/O devices may be accessed through this array. You should define the same array in your “lab8.c” file so that you may access control registers and other memory-mapped devices. When using the output compare system to generate notes on your speaker, you should use the polling technique rather than interrupts to service your output compare. Setting up the interrupt system in C is rather involved and goes beyond the scope of this lab. Instead, simply poll the output compare flags in the TFLG1 register to determine when a successful output compare is made. PROGRAMMING SUGGESTIONS You are free to write your code any way you would like, as long as it accomplishes the program requirements (and is written in C). The following is offered merely as a suggestion of one possible way to break your program into functions. MAIN: Your main routine should call functions to initialize your LCD and your output compare systems. Once initialization is complete, you should call a function to play the Windows XP startup theme. Finally, you should call a function to display the appropriate text on your LCD display. INIT_OC: The INIT_OC function can perform the same output compare initialization steps that you performed in the synthesizer lab. However, since you are encouraged to use polling instead of interrupts, there is no need to initialize the interrupt system. INIT_LCD: The INIT_LCD function can perform the same LCD initialization steps that you performed in the LCD lab. Delays can be written using common looping constructs (for, while, etc.) available in the C language. LCD_CHAR: The LCD_CHAR function can send a character to the LCD display much like the OUT_CHAR function sends a character to the computer screen in the “hello.c” example. LCD_STRING: The LCD_STRING function can send a string of text to the LCD display by repeatedly calling the LCD_CHAR function. This is similar to the OUT_STRING function in the “hello.c” example. PLAY_NOTE: The PLAY_NOTE function can take as arguments the note frequency and duration. This function can make the necessary changes to the output compare system to play the desired note for the desired amount of time. IN-LAB PROCEDURE 1. Run the lab8.s19 program from address $8000 in SRAM by downloading it to your board and typing “go 8000” at the monitor prompt. Note that you can not download to your board unless the monitor boot mode is set to “normal mode”. 2. Run the program again, this time putting your board into “bypass mode” so that the program runs immediately following reset. 3. Create lab8.lst and visual compare it to the lab8.c file. You do not need to annotate anything with the lab8 files. PRE-LAB QUESTIONS 1. At what beginning address does the C compiler place your program? At what address does it place your data? How do you adjust this? 2. How could you modify your board to play the Windows XP startup theme after reset without ever having to load the program into RAM? If you have time, you could try this in lab! WRITE-UP You will submit the following to your TA: 1. The printout of your annotated hello.c, hello.lst and hello.txt files and the memory.x file you used for the hello.c execution. 2. The printout of your final C program and “memory.x” file. 3. A media copy containing your hello and lab8 .c, ..lst, .txt, .x, and .s19 files. 4. Answers to Pre-Lab questions.