You are on page 1of 8

Published on Your Electronics Open Source (http://dev.emcelettronica.


Home > Blog > brumbarchris's blog > Contenuti

Getting Started with CodeWarrior IDE from

By brumbarchris
Created May 15 2009 - 08:09

CodeWarrior Development Studio is a complete Integrated Development Environment (IDE) that

provides a highly visual and automated framework to accelerate the development of complex embedded
applications using Freescale processors. One of the best features of this environment is its support across
the most used platforms available to developers: Windows, Linux, Mac, Solaris. Also special versions exist
for specialised operating systems destined for PlayStation 2, Nintendo, Wii. Palm OS and Symbian OS can
also run CodeWarrior to some extent. The IDE is centred on C and C++ compilers and includes all the
tools necessary to complete an embedded (software) project: text editors, compilers, simulators,
debuggers etc.

Due to the huge complexity of a single tool that would support the broad range of Freescale products,
special and smaller versions of CodeWarrior are available being specialised in dealing with particular
families and architectures. This also allows for cost savings, taking into account that if you plan to use the
CodeWarrior for developing on ColdFire architectures, you would hardly need any StarCore DSP
functionality. Thus, various versions of the environment are available for purchasing and download

-56800/E Digital Signal Controllers

-68k Embedded Systems
-ColdFire architectures
-HCS12(X) microcontrollers
-RS08/HC microcontrollers
-mobileGT applications
-MPC55XX processor family
-Power Architecture Netcomm Processors
-StarCore DSP

Short history

CodeWarrior was initially developed by a company called Metrowerks (Canadian) and was initially
targeting the PowerPC of the Macintosh. However, after the 1999 acquisition of Metrowerks by Motorola
(the big fish eats the little fish) the scope of CodeWarrior was changed to embedded systems; after 2005
support for Mac processors was discontinued completely. Nowadays the IDE belongs to Freescale and
supports all the above mentioned targets.
On a more mundane note, the name of CodeWarrior was inspired by the Mad Max film series (Mad Max 2:
The Road Warrior)

Get started
The company I work for has recently started using HCS12 micros so we had to purchase the CodeWarrior
version dealing with them. Using a new programming environment might not have been so difficult for our
software developers (they have probably seen tens of them so far), but it was for me (I am a hardware
engineer myself). Normally I should not have dealt with writing any code at all, but due to the strain put on
all the people in the company (or on the ?resources?, as the managers put it) I had to write small pieces of
code just to test various sections of the hardware we are designing.

When I was first told we are using CodeWarrior I just told myself it must be for Freescale just what MPLAB
is for Microchip, or what AVR Studio is for Atmel (I am more familiar with these). And I was not far from the
truth (of course professional software developers might argue against this).
I tried to structure the initial experience with this powerful development environment in a few easy to follow

Step 1 ? download and installation

CodeWarrior costs money. It does not come cheap. Fortunately, Freescale makes available free versions
which only allow limited code sizes to be built. These versions are more than enough to get a heads-up on
how it looks and works.
Visit Freescale [1] in order to download any of the available packages. Because this was what I needed, I
have downloaded the special version of the HCS12X Microcontroller family and this is what I will refer to
below. Once you have downloaded it, the installation procedure is the familiar Windows style ?Next?->
?Next?->?Finish?-?Launch? process.

Alternatively, Freescale also allows the download of fully functional versions of CodeWarrior, but only for a
30-day evaluation period.

Step 2 ? Creating the project

After you launch CodeWarrior, from the top menu bar choose File->New, which will pop up the ?New?
widow which allows you to start a wizard. Select the Wizard option and enter a name for your project (in
this case, I selected the name ?Tutorial?:

Go through the wizard, selecting the MC9S12E128 as the derivation that you want to compile for and C as
the set of languages to work with:
The project wizard has quite a few pages. Go through all of them selecting successively: no Processor
Expert, no set up for PC-lint, ANSI startup code, no supported floating point format, banked memory
model. On the last page, the wizard lets you select a debugger/programmer or a simulator. For now, just
select the simulator, as you will always be able to switch to a physical device once the project has started.
And I do like to simulate my code:
Step 3 ? Writing the code
Following the successful completion of the last step in the wizard, CodeWarrior will display a Project
window docked on the left side of the environment. To get to the actual files where you write the code, you
will have to click on the small ?+? sign near the ?Sources? folder, which will reveal the existing files in your
code. For now, there are only two, and you will want to edit the main.c file, by double clicking on it.

The code automatically generated is kept to a minimum and should not be too overhelming even for a

#include /* common defines and macros */

#include /* derivative information */
void main(void) {
/* put your own code here */
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */

The code I needed to write in the beginning was pretty simple. The microcontroller on our project also had
the purpose (amongst others) to turn on the power supply for a different part of the circuit by toggling a pin
high. If I managed to do this, I would have been able to test the entire circuit with no help from the software
guys! They are of course, important ?resources? not to be wasted on such trivial tasks like turning a pin
high or low.
To turn pin PB7 high you only need to write two registers: PORTB and DDRB. Fortunately, all registers are
defined in the mc9s12e128.h file which is included in the beginning of the code, so I did not even have to
search the datasheet for the register addresses. The DDRB register is the direction register for PORTB
pins. When port B is operating as a general-purpose I/O port,
DDRB determines the primary direction for each port B pin. Logic 1 cause the associated port pin to be an
output and a 0 causes the associated pin to be a high-impedance input. The value in a DDR bit also affects

#include /* common defines and macros */

#include /* derivative information */
void main(void) {
/* put your own code here */
for(;;) {} /* wait forever */
/* please make sure that you never leave this function */

Before downloading it to the target, I wanted to make sure I got everything right and I wanted to test the
code. .h>.h>.h>.h>

Step 4 ? Simulating the code


To simulate the code two steps are needed: first you need to build it (using compiler, linker etc) and then
you need to initialise the simulation. This is as simple as two clicks. To make the code, just hit F7.
Alternatively you may use the menu Project->Make. You should get no errors if your code is as simple as
Before you initialise the simulation you might want to have a look at all the simulation settings that can be
made. The corresponding window may be invoked by ALT+F7 or you may launch it with the menu Edit-
>Full Chip simulation Settings. Just by seeing the many tweaks and settings you can make here, you can
get a pretty good idea of how powerful and useful the simulator (and hence the environment) may be:
For now, just leave the settings as they are and close the window. To actually start the simulation, you
need to choose from the menu Project->Debug, or alternatively just hit F5. This will open a completely new
window of CodeWarrior (which is actually to big for a print screen) containing all the relevant sub-windows
necessary for simulation (source code, disassembly window, memory map, chip settings etc).
A neat feature of CodeWarrior is that it allows you to have a visual representation of the pin states, through
a component called IO_LED. To activate the component, in the simulation window, chose from the menu
Component->Open. This will display a broad array of ?components? to choose from, the component being
basically a graphic way of displaying information. From all the options available, please choose the
?io_led? one:

This will activate a new child window displaying 8 small round ?LEDs? to which you can associate a data
register address and a direction register address:.h>.h>.h>.h>

To make the association, I needed to consult the datasheet to find out the register addresses for PORTB
and DDRB. These are 0x0001 for PORTB and 0x0003 for DDRB and in order to associate these
addresses with the LED component you need to right click on the LEDs small window and in the newly
open dialog box enter these two addresses:
Once this last step is finished, you may consider yourself ready to commence the simulation. This can be
easily done from the green ?Start? button available on the top toolbar, or alternatively by pressing F5 again:

The simulation is fast, and once the lines of code setting the values for DDRB and PORTB are reached,
you will notice the LEDs change colour to this:

I guess red means logic high and green means logic low (it?s quite the other way around from what I would
make of things, but of course, this is just a detail).

Step 5 ? Downloading to the target


From now on it really gets dependent on the programmer you have. To download the compiled code to the
real microcontroller, in the simulation window that has been created at the previous step select Component-
>Set Connection. This will open a new window where you will be able to select the programmer that you

Once you complete the above 5 steps you should be able to go ahead on your own. CodeWarrior itself is
not difficult to use, and the sheer array of options makes it very flexible.
More information and download under: CodeWarrior Development Tools [2]

Read the Italian version: Iniziare con CodeWarrior IDE della Freescale [3]

If you want to know more about this Freescale product, please submit your request to Arrow Italy using
this form [4].
NOTE: this form is valid ONLY for Companies or Customers based in Italy and working in the Italian area.

Embedded CodeWarrior Freescale ide programming environment Tutorial


Source URL: