Tutorial 1: Programming With Codewarrior Ide
Tutorial 1: Programming With Codewarrior Ide
29/10/2007
Tutorial 1
Programming with CodeWarrior IDE
This document gives you an introduction to the programming environment you will be
using in the course for the development of embedded software systems for the MCF5213
microcontroller. You will also be introduced to the main I/O devices that are available.
Step-by-step instructions will be provided to guide you through the development of
simple applications. It is important that you understand the motives and the activities of
each of these steps. In future laboratory exercises, it will be assumed that you are capable
of reproducing these steps, as well as modify them to suite your needs. For this reason,
you should take the opportunity to enquire about any uncertainties you meet. Try to
answer the questions posed as they will give you more insight into the environment.
The tutorial is divided into 3 sections.
• Part A introduces the laboratory hardware.
• Part B introduces the CodeWarrior programming environment, , and lets you
experiment with some C programming
• Part C introduces the basic I/O modules built-in the MCF5213. This will give
you extra opportunities to practice your programming skills.
MCF5213EVB
Interface Card
Motor Card
Power
UART0
Microcontroller
LCD
Switches
Microcontroller
Potentiometer
Keyboard
LEDs
1
Reference: Wikipedia, http://en.wikipedia.org/wiki/Integrated_development_environment
Embedded Control Systems course, Autumn 2007. (05/11/2007) Page 3 of 19
Course home page: http://www.md.kth.se/mmk/gru/mda/mf2008/
Programming with CodeWarrior IDE
29/10/2007
3. We will now use the project wizard to help us create a C program, specific for the
M5213EVB board which contains a MCF5213 microcontroller.
a. Select FileÆNew from the top menu. You can also use the shortcut
Cltr+Shift+N.
b. A dialog box appears. From the Project frame, select ColdFire
Stationery.
c. Define the Project name and its Location.
1. Project name: sample
2. Location: Choose your own location! Note that the wizard
automatically names the final folder destination to match that of
the project name. This is for your convenience only, and you can
choose any folder name desired.
d. Select OK
e. You are now prompted to select a project Stationery
1. You will be developing code for the 5213 microcontroller. Click
on the + sign to the left of CF_M5213EVB to further expand its
submenu.
2. You will be developing C code. Select C from the submenu that
appears.
3. Are you sure you selected the right microcontroller?
M5213EVB?
4. Select OK.
4. The wizard now creates the necessary files and configurations to help you start
with a simple application.
5. Now is a good time to see what the wizard has done to your file system.
a. Go to the file location where you specified the project to be created.
b. Browse through the various directories and files created under this
directory
c. Don’t be afraid to open any of them! Any interesting files?
1. the .mcp file is your project file containing all the necessary
information about your project. Double-clicking on this file will
open your project in CodeWarrior.
2. Under the Source directory, you will see a collection of C
source code files! (Surprise! Surprise!) Most interesting is the
main.c file that you will encounter very shortly. Double click on
it anyway and see what it contains!
3. The Include directory contains many support source code files
that you might find useful if you need to use any of the modules
of the microcontroller such as PWM, ADC, timers, etc.
6. Back to the CodeWarrior IDE! A new window (the project window) appears
showing two important components of your project: (1) The list of files
constituting your projects and (2) the list of targets onto which the application will
be built.
Target list
Debug
Make
Project files
Target options
a. Files - The files are categorised into different groups such as Source,
Linker Command Files, etc. The location of the project files in these
groups does not affect the functionality of the IDE, and is only
advantageous for you to stay in control and understand the different types
and categories of files involved.
1. Under the Source group, you will find a main.c file. Open this
file by double-clicking on it.
1. Does it look familiar?
2. What do you think the program will do when it runs?
2. Under the Linker Command Files group, you will see two
linker configuration files that specify how the files are to be built
and linked together.
3. Under the Support files group, you will see a list of files of
various types such as C-source code files and assembler code
(files with the ‘.s’ extension) The files are automatically created
by the Project wizard to initialize your hardware appropriately
depending on the options you selected. In most cases, you will
not need to modify any of these files but it is important to be
aware of their presence, and ensure that they are not deleted by
mistake.
4. The Runtime, FP, C, and UART lib group contains a list of
default library files that you will most likely need during
development.
5. Try to create a new Group called Extra files!
Kill Thread
Step Over
Step Into
d. The debugger is now waiting for instructions to execute and monitor your
program. You can choose to execute the program to termination, or to step
through it one instruction at a time. Move your mouse over (do not click)
each of the top buttons illustrated above and read what they try to do.
e. For now, we want to run the program to termination, by clicking on the
Run button.
1. What do you observe?
2. Does the program behave like you expected?
f. Once you’re satisfied with your simple observation, terminate the
execution by clicking on the Kill Thread button.
g. If you simply try to close the debugger window, you will get a warning
that there exists a running process that is currently being controlled by the
debugger. You will be given the option to immediately Kill the process or
Resume execution. Unless it is necessary, try not to kill the process in
this way.
To experiment with general purpose I/O functionality we will experiment with the 4
LEDs that are setup on the evaluation board. These 4 pins are connected to the TC port of
the microcontroller, and we will hence develop the code necessary to configure this TC
port.
1. On the microcontroller, first ensure that the LED_EN jumper is ON
2. Before we can output on these pins, we need to configure them for I/O output.
a. The register MCF_GPIO_PTCPAR (Port Assignment Register), shown
below, allows each pin to be configured between the GPIO function and
its primary function (in this case, the TC port’s primary function is a
Digital Timer Input)