Whether you are porting your existing C code to the GNU
compiler or creating an application from scratch, learning to use any new
compiler and development environment can be time consuming. For those who are new to GCC, setting up
compiler options, linker scripts, and target startup code takes even more
time. And, if you have never developed
a C application for an embedded system, then you might be working late a few
nights this week. PKGCFZ PRO reduces
your down time by simplifying all of these tasks. Follow the steps below to speed through the development process.
1
Creating a ColdFire Application from Scratch
2
Configuring the Compiler and Target Application
3
Customizing the ColdFire Application
4
Adding Your Own Source Files
5
Changing the Memory Map
6
Configuring Chip Select Registers
7
Customizing the Vector Table and ISRs
8
Conclusion
Even if you are not going to use P&E's default source
files for your application, begin by making a WinIDE project from a
template. This will automatically
configure the compiler for your target processor.
After installing PKGCFZ PRO, launch WinIDE from the Programs
folder in the Windows Start menu. In
the WinIDE Environment menu, select New Project from Template. A list of all ColdFire 52xx processors and
select commercial development boards will appear. For this example, we'll select the template EVB_PE_DEV5213CF,
which will create a project for the P&E ColdFire 5213 development
board.

If listed, select the template for your development
board. If you are using a custom board
or if your board is not listed, select the general template for your target
processor.
Next, WinIDE will ask you three questions:
Where would you like your new project folder to be located?

What is the name of your new project?

Where is the GNU compiler?

WinIDE will automatically select the location of the
compiler.
At this point, WinIDE will create your new project and
default source files, and it will configure the compiler settings. If you do not want to use the default
P&E files, we'll discuss replacing them below.
You will see a list of project files in the right pane of
WinIDE. Left-click on a file name to
open that file for editing, such as the file main.c:

Hit the F4 key, or use the WinIDE toolbar button, to compile
your code. If there are no compile time
errors, then the GNU software will produce an ELF/DWARF2.0 file, such as
main.elf, for debugging and a Freescale s-record file, such as main.s19, for
flash programming. After a successful
compile, WinIDE will look similar to this:

Above, notice that the WinIDE status bar indicates that no
errors occurred during compilation.
When a compilation fails, WinIDE will highlight the problem
code, if applicable, and display the first error message in the WinIDE status
bar. Notice that all the compiler
output messages appear in the file err.log.

Return to top
You will need to be concerned with two groups of user
settings. Access compilation settings through WinIDE's dialogs. See the linker script to edit the ColdFire application settings that determine the
final memory map. In many cases, when
you create a project from a template, WinIDE automatically configures both the
compilation settings and the target application settings.
2.1 Compilation Settings
Access all of the compilation settings through WinIDE's
Environment menu, Environment Settings dialog, Assembler/Compiler tab, shown
here:

From the Assembler/Compiler tab, four additional dialogs are
available. The WinIDE Error Options
dialog controls WinIDE's handling of compiler errors. The Compiler Options (General) dialog contains settings that
enable debug information and control compiler output. The Compiler Options (Paths) dialog sets all of the path
information for the compilation, including library paths, output paths, and the
location of the linker script. Use the
Build Dialog to specify the names of the source files to be compiled.
Leave all of these dialog settings unaltered for now. We will look more closely at the Build
Dialog and the Compiler Options (Paths) dialog, below.
2.2 Target Application Settings
The linker script controls the final memory layout of the
ColdFire application. Using the default
P&E linker script, you will need to check just a few items located at the
top of the linker script file. Locate
the name of the P&E linker script in the Compiler Options (Paths)
dialog. Access this dialog through the
WinIDE Environment menu, Environment Settings dialog, Assembler/Compiler tab.

In this example, the linker script name is pe_MCF521x.ld.
Close all of the dialog windows and click on the linker
script name in the right pane of WinIDE.
The linker script contents appear similar to below. The top of this file is the user section
that contains linker script variables.
Use these linker script variables to control the memory map of your
application. You may or may not need to
change these values to suit your target system. See below for more information about changing the application
memory map.

Now, you will want to recompile the new project, this time
ensuring that the compilation settings and memory map are suitable for your
target system. You will also need to
replace or change the P&E default source files to perform your specific
task. Read the next section to get your
application running.
Return to top
After creating the new project from a template, you need to
ensure that the ColdFire application memory map is compatible with your target
system. Likely, you will find yourself
in one of these situations:
3.1 You created a
project with a template for a specific evaluation board, such as
EVB_PE_DEV5213CF, and you want to run the default P&E code on your board.
You do not need to change the compilation settings or target
application settings.. Ensure that the
development board is in its default hardware configuration. The s-record and ELF/DWARF2.0 files,
produced during compilation, are ready for programming and debugging.
3.2 You created a project with a general
template, such as MCF5212_5213, and you want to run the default P&E code.
You do not need to change any compilation settings in the
Assembler/Compiler tab. However, you
need to check the top of the linker script to be sure that the default memory
map is suitable for your target system.
You may also need to configure chip select registers during application
startup. See the sections below, "Changing the Memory Map" and "Configuring Chip Select
Registers".
3.3 You created a
project with any C template, and you would like to change or replace the
default P&E code. However, you want
to use the P&E initialization code (the crt0 startup code), vector table,
and linker script.
Four source files operate as a group to frame the P&E
ColdFire application: the linker
script, crt0 startup code, user initialization hooks, and the vector table and
interrupt service routines. If you
modify one of these files outside of what is described in the documentation,
you may need to supply your own linker script, startup code, and vector table
code. You may replace any other default
source file except the linker script, startup code (such as pe_crt0_MCF521x.S),
user hooks (pe_hooks.c), and vector table and ISRs (such as pe_vectors_DEV5213CF.c).
How do you make your source code fit in with the default
application files? Add your files to
the compilation; add interrupt handlers, check the memory map in the linker
script, and add user initialization code.
To add or remove files from the compilation, you will need to
change the list of files in the Build Dialog.
See the section below "Adding Your Own Source Files".
To add interrupt service routines and to edit the vector
table, see "Customizing the Vector Table and ISRs".
You need to check the top of the linker script to be sure
that the default memory map is suitable for your target system. You may need to configure chip select
registers during application startup.
See the sections below, "Changing the Memory Map" and
"Configuring Chip Select Registers".
3.4 You created a
project with any C template, and you will not be using any of the P&E
default files, including startup code, vector table, and linker script.
To add or remove files from the compilation, you will need
to change the list of files in the Build Dialog. See the section below "Adding Your Own Source
Files". You will need to specify
explicitly the name of your startup code, if any.
You will need to specify your own linker script file. See the section "Changing the Memory
Map".
Return to top
From the WinIDE Environment menu, Environment Settings
dialog, Assembler/Compiler tab, open the Build Dialog. This dialog lists all of the file names that
will be passed to GCC. You may include
either C or assembly source files.
The Build Dialog should list the name of the ColdFire
startup file, such as pe_crt0_MCF521x.S.
The startup code calls the user initialization routines in the file
pe_hooks.c. The vector table and
interrupt service routines are located in the file pe_vectors_DEV5213CF.c.

In addition to the linker script, the startup code,
initialization hooks, and vector table/ISR code comprise the P&E ColdFire
application framework. If you are using
these files, add your own source files to the build to produce your
application. If you want to use your
own linker script, startup code, and vector table/ISR code, simply remove the
startup code, initialization hooks, and vector table from the Build Dialog and
specify the new linker script in the Compiler Options (Paths) dialog. We discuss adding a new linker script
below.
When adding your own files to the Build Dialog, you will
also want to add them to the right pane of WinIDE. Do this in the WinIDE Environment menu, Add Files to
Project. This will allow you to quickly
open your source file.
Return to top
If you created a project for a specific evaluation board,
such as EVB_PE_DEV5213CF, you will not need to change the linker script. The default memory map will be compatible
with your board. However, you may
desire to change the memory map. If you
created a project for a board using a general template, such as MCF5212_5213,
then you will need to be sure that the default memory map is compatible with
your ColdFire system.
The linker script controls the memory map of the ColdFire
application. Open the linker script and
look at the top of the file, which is the user section of the linker
script. Several linker script variables
must be set to be compatible with your target system. All of these linker script variables are located at the top of
the linker script. Do not change the
linker script below the user section, which is clearly marked in the file.
The user should examine the following linker script
variables, ensuring that their values are appropriate for the target system.
__application_load_address: The value of this variable is the base
address of the application. This is the
address of the executable code at load time.
If you will be programming your application to flash, this should equal
the base address of flash.
__application_run_address: This is an optional variable and is
undefined by default. This is the address of the executable code at run time. If defined, startup code will copy both executable code and global/static
variables to this location, for example, from flash to RAM.
__global_data_run_addr:
This is an optional variable and is defined by default. The value is the location of global/static
variables at run time. If defined,
startup code will copy global/static variables to this location, for example,
from flash to RAM.
__stack_start:
This value is the initial value of the stack pointer. Valid RAM must
exist at this location.
__heap_start:
This is an optional variable and is undefined by default. This value is the location of the beginning
of the heap in RAM. If undefined, the
linker script automatically sets the location of the heap.
These linker
script variables are common to all of the template projects. Note, there may be additional, target
specific variables as well.

You may choose to use your own linker script. To specify the name of your own linker
script, open the Compiler Options (Paths) dialog, as shown in the section
above. Remember that the default linker
script, startup code, and vector table/ISR code act as a unit, so the
replacement of one of these files will require that you supply all of them.
Return to top
The file pe_hooks.c contains user initialization hooks. The startup code, such as pe_crt0_MCF521x.S,
calls the hook routines. The routines
are useful for custom initialization tasks, such as chip select initialization.
Look at the P&E startup code, such as pe_crt0_MCF521x.S,
and the routine memory_init_hook in the file pe_hooks.c. Target execution begins in the startup code,
which calls memory_init_hook. This
routine memory_init_hook is the proper location for chip select initialization.
Return to top
The vector table and interrupt service routines are located
in a file such as pe_vectors_DEV5213CF.c.
To add your own ISR, simply call the user ISR from the default ISR, as
below:

By default, the linker script automatically sets the vector
table location to equal the base address of the application. Although the user may change the application
base address in the linker script, the user should not change the relative
location of the vector table. If you
are using your own linker script, you must create your own vector table and set
its location in your linker script.
Return to top
To state concisely, create a ColdFire 52xx application by
doing the following:
1. In WinIDE, create
a project from a template.
2. In the WinIDE
Build Dialog, replace the default files with your own files, except the startup
code (such as pe_crt0.S), user initialization hook (such as pe_hooks.c), and
the vector table and interrupt service routines (such as pe_vectors.c). Add your files to the right pane of WinIDE
for quick access.
3. Add custom
initialization code, such as chip select configuration code, to the user
initialization hooks.
4. Call your own
interrupt service routines from the default ISRs.
5. Check the top of
the linker script to be sure that the memory map is compatible with your target
system.
6. Compile your
project to produce an s-record file and ELF/DWARF2.0 file.
Further help is available at the P&E website, including
FAQs, user forums, links to GNU resources on the web, and documentation
downloads. PKGCFZ Pro includes Quick
Start Guides, a User's Manual that details WinIDE's interaction with GCC, and
the Application Framework and Solutions Guide that fully explains the default
P&E ColdFire application and provides answers to many specific questions.
Return to top