LABS12CINTRO02 - Computer Engineering

sanatoriumdrumElectronics - Devices

Nov 25, 2013 (3 years and 9 months ago)

160 views




www.freescale.com/universityprogram
s



Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc.

All other product or service names are the property o
f their respective owners

© Freescale Semiconductor, Inc. 2006.

Document Number:
LABS12CINTRO02

/
REV 1















Laboratory Short Course

Software Development





Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

1


Reading this Document


Answers provided to the Instructor assume that the reader is using Freescale HCS12C Family Student Learning Kit,
and CodeWarrior development software.


This shor
t course has been created using an adapted version of the Process Oriented Guided
Inquiry
Learning (POGIL)
method. For more information visit
www.pogil.org






Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

2

Overview

The hardware we saw in the microcontroller modu
le is only part of an embedded system. The
software part is often the mostly costly part of an embedded system. Choosing appropriate software
development tools can reduce the overall cost of a system by making it easier to develop and test.

Focus and Moti
vate:

Some of the statistics of
the cost of developing
the software for an
embedded system can
be imparted to the
students. Often this cost
greatly exceeds the cost
of the hardware,
sometimes by orders of
magnitude.

Years ago a
study estimated that
fully d
esigned,
debugged and
documented code is
produced at a rate of 10
lines per day.
More
recently
Ganssle
(
www.ganssle.com
)
estimates the cost of
producing embedded
code is $20
-

$50 per
line.

Learning Objectives

In th
is module you will learn about locating various parts of your program in the correct memory
types in your microcontroller. You will see an overview of the software development process and
some of the tools that are available.

Teach:

It is vital that the
s
tudents, especially
those writing in a high
-
level language like C or
C++, understand that
the program has to be
located in the correct
type of memory. Thus,
even software
programmers need to
understand the
organization of the
hardware.

Success Criteria

Wh
en you complete this module you will be able to identify the types of memory used for various
parts of the program. You will know what software development tools are available to do what jobs.


More Resources and Further Information

Cady, Fredrick M.,
Sof
tware and Hardware Engineering: Assembly and C Programming for the
Freescale HCS12 Microcontroller
, 2
nd

edition. (New York: Oxfor
d University Press,
Inc
., 2008),
Chapter 2
, General Principles of Microcontrollers
,

and Chapter 9, Debugging HCS12 Programs.







Software
Development


Applications / Solutions / Products




Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

3

Software/Firmware Development


Table 1 shows the memory map of a typical microcontroller with RAM for variable storage and RO
M
for the program. The location

of the various types of memory is often fixed by the microcontroller
design and thus, as
prog
rammers, we must take into account the location of each type of memory
and locate each correctly.
Table
2

shows where the various parts of our program must be located to
work in an embedded system
.

You need a softw
are development tool
, such as CodeWarrior

Ⱐwi瑨⁦eatu牥s⁳uch as a⁳ou牣e⁦ile
edi瑯rⰠ牥loca瑡ble⁡ssemble爠and⁃⁡nd⁃⬫ compile牳Ⱐlinke爬rand⁡ simula瑯爯rebugge爠ro⁦acili瑡瑥
developing⁹our⁳o晴wa牥⁩n⁡ssemblyanguageⰠa⁨igh
-
level language like
䌠Cr⁃⬫Ⱐor⁰erhaps
bo瑨.


Table
1
. Memory map with both RAM and ROM (reprinted with permission of Oxford
University Press,
Inc
.).

$0000

I/O Interface

Registers


$01FF

$0200

1 Kbytes

EEPROM


$03FF

$04
00

None



$07FF

$0800

2 Kbytes

RAM



$0FFF

$8000

32 Kbytes

Flash


$FFFF


Background:

At this point the
students may or may
not have had a
programming language
experience. Many have,
but mostly in a desktop
environment.
Developing code for an
embedded system

requires the student to
understand the
architecture of the
embedded system and
how it differs from the
desktop.

The CodeWarrior®
Integrated Development
Environment contains a
source file editor,
relocatable assembler,
C and C++ compilers,
linker, and
simu
lator/debugger. It is
especially powerful for
debugging because it
supports the
background debugging
mode available in
Freescale HCS
-
family
processors.

Anecdote:

An unknown author,
critical of many firmware
programs being written,
once referred to these
p
rograms as mushware!

Teach:

Flash EEPROM uses
EEPROM
-
type
electronic cells but they
are organized in such a
way that cells cannot be
individually erased and
reprogrammed. This
must be done in banks
of cells. The advantage
of this memory
architecture is th
at the
erasure and
reprogramming is
accomplished faster
than with the "standard"
EEPROM. Thus the
name
Flash EEPROM
.

Teach:





Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

4


Table
2
. RAM and ROM memory used in an embedded application (reprinted
with permission of Oxford University Press,
Inc
.)

Memory type

Pro
gram use

Flash

1. All program code.

2. Constants such as messages and lookup tables.

3. Any other information that does not change.

EEPROM

1. Variables that must remain when the power is
turned off.

RAM

1. Program variables and data.

2. Stack data stora
ge.



Stimulate 1.


1.

Why must an embedded systems program code be located in ROM when a desktop system
application is located in RAM?

Answer:

1)
Embedded system
code must be there
when the power is
turned on. A desktop
system has an
operating system that
loads the ap
plication
program into RAM for
execution.

Creating a
Microcontroller

Program

An absolute program is one in which all functions are in one source file and assembled/compiled
together.
A relocatable program is one in which modules can be developed independe
ntly of one
another and then combined to create the final program.

Even though you may be writing small
programs as you start to learn about microcontrollers, which could be done using an absolute
assembler,
you will soon progress to larger and more comple
x projects. When using a relocatable
assembler/compiler, large projects can
be
partitioned

into smaller, more easily understood elements
that can be allocated to different programmers (perhaps, if the project is large enough) and then
combined to create th
e final system. Each of the separate elements are assembled or compiled into
what are know as object modules that are then combined using a linker.

Teach:

It is useful to contrast
the operation of the
relocatable assembler
with the absolute
assembler. In

an
absolute assembler, the
student must have the
entire program in the
source file. This
discourages modular
program development
and introduces more
interdependencies that
can lead to program
bugs.

Using High
-
Level Languages

Writing programs in assembly
language is tedious and time consuming for all but the smallest of
programs.
A high
-
level language, such as C or C++, can greatly increase our programming
Teach:

The student can be
s
hown that a simple,



Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

5

efficiency
.
Nevertheless, in the final analysis the microcontroller's memory must have the operation
code and operand bytes.

Thus, although we rarely see the assembly code, the compiler
compiles

the source program to produce the equivalent operation code and operand bytes that an equivalent
assembly language program produces.

program, such as the C
program "Hello World!",
consists of a sequence
of computer instructions
(the assembly
language) that are
executed when the
program runs.

Linking the Object Modules Together

After we have created source files in a
ssembly language (module1.asm) and in C (module2.c) and
assembled and compiled them to object files (module1.obj, module2.obj), a

linker

program
links

them together, and
locates

all
program segments in the proper
addresses
and
produce
s

the
executable file.

You must provide
a
linker parameter

file (
.prm
)
to specify the memory type locations
that are shown in
Table
1
.

Source File 1
(module1.asm)
Relocatable
Assembler
Object File 1
(module1.obj)
Time
Source File 2
(module2.c)
Compiler
Object File 2
(module2.obj)
Time
Library of
Object Files
(file.lib)
Linker
Program
Code and Data
Location Information
(name.prm)
Absolute
File
(name.abs)

Figure
1

Linker program

(reprinted wi
th permission of
Oxford University Press,
Inc
.
)
.

Teach:

The linker program is
sometimes called a
linker/locater

because
of the two actions it
performs.

Debugging

Debugging and testing is an important part of our software development process because,
unfo
rtunately, none of us write programs that work flawlessly the first time and forever. Debugging is
like solving a mystery and an approach that analyzes the problem will be most successful in tracking
down the
problem.
An analytical debugging approach can b
e very efficient in solving your mystery.
With this strategy we know what should happen and then we observe what really happens. Once we
find out where the program deviates from the model, we are well along our way to finding out why it
Teach:

The idea that the
software should work
flawlessly forever
s
hould be impressed
upon the student. This
implies considerable



Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

6

is going wrong and
what will be needed to fix it.

Input
Data Set
Input
Data Set
Stepwise
Program
Model
Stepwise
Actual
Program
Stepwise
Expected
Outputs
Stepwise
Actual
Outputs
Expected
Next Program
Step
Actual
Next Program
Step
Debugging
the Data
Debugging
the Program
Flow
What we think will happen.
What actually happens.


Figure
2

Analytical debugging model (reprinted with permission of Oxford University
Press,
Inc
.).

testing is required, a
concept many students
do not understand right
away.

Anecdote:

Often, when beginning
students are asked
what their program is
doing, they respond
with "Nothing!" This is
a
good time to remind
them that a computer is
always

doing
something. Debugging
means finding out what
the computer is doing
actually when it is not
doing what you want it
to.

Enrichment:

Check out the Ganssle
group for some great
information on
embedded
system
debugging and other
topics.
http://www.ganssle.com/

Explore 1.


1.

What are the components of the software development system you are using?

2.

If there is an assembler, is it a relocatable or absolute assembler?

3.

Find the memory map of your targ
e
t.

Answers:

See Ins
tructor’s Notes
below.

Stimulate 2.


1.

Which parts of your program are located in RAM?

2.

Which parts of your program are located in ROM?

3.

What does an assembler do?

4.

What does a compiler do?

5.

How does a compiler differ from an assembler?

6.

What does a linker do?

7.

What is a libr
ary file and how is it used?

Answers:

1
)

Variable data and the
stack.

2
)

Code and constants.

3
)

Converts an
assembly language
program to the machine
code to be loaded into
memory.

4
)

Converts a high
-
level



Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

7

language into the
machine code to be
loaded into me
mory.

5
)

A compiler often may
produce an intermediate
assembly language file
to be assembled.

6
)

Links together
separately assembled
and compiled modules
and locates them in the
correct memory.

7
)

A library file contains
modules that have been
tested and
a
ssembled/compiled. It
allows us to use
previously developed
code in our programs.

Problem 1.


1.

Write a very simple C (or other high
-
level language) program, compile it, and view the
assembly code that the compiler produces. Roughly how many, on average, assembly
lang
uage instructions are generated by each C statement.


Communication


Inter
-
Group

Share your group's compiled program for
Problem 1

with another group. See what differences there
are in the two programs and how

the compiler produces assembly code for each.


Reflection on Learning

1.

What was the most useful thing you learned during this session?

2.

What discovery or insight about debugging software did you make today?





Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

8


Instructor's Notes


Explore 1.


1.

What are the components

of the software development system you are using?

2.

If there is an assembler, is it a relocatable or absolute assembler?

3.

Find the memory map of your targuet.






Freescale Semiconductor

LABS12CINTRO02
,
Rev 1

9

Revision History


Revision

Comments

Author

0

Initial Release

Fred Cady

1

Miscellaneous

text

edits

Fred Cady









Freescale™ and the Freesc
ale logo are trademarks of Freescale Semiconductor, Inc. All other
product or service names are the property of their respective owners. ARM is the registered
trademark of ARM Limited. ARM9, ARM11, and ARML210™ are the trademarks of ARM Limited.
Java and

all other Java
-
based marks are trademarks or registered trademarks of Sun
Microsystems, Inc. in the U.S. and other countries. The “PowerPC” name is a trademark of IBM
Corp. and used under license.

© Freescale Semiconductor, Inc. 2006.

Document Number:
L
ABS12CINTRO02

/
REV 1

How to Reach Us:





Home Page:

www.freescale.com


Web Support:

http://www.freescale.com/support


USA/Europe or Locations Not Listed:

Freescale Semiconductor, Inc.

Technical Information Center, EL516

2100 East Elliot Road

Tempe, A
rizona 85284

+1
-
800
-
521
-
6274 or +1
-
480
-
768
-
2130

www.freescale.com/support


Europe, Middle East, and Africa:

Freescale Halbleiter Deutschland GmbH

Technical Information Center

Schatzbogen 7

81829 Muenchen, Germany

+44 1296 380 456 (English)

+46 8 52200080 (
English)

+49 89 92103 559 (German)

+33 1 69 35 48 48 (French)

www.freescale.com/support


Japan
:

Freescale Semiconductor Japan Ltd.

Headquarters

ARCO Tower 15F

1
-
8
-
1, Shimo
-
Meguro, Meguro
-
ku,

Tokyo 153
-
0064

Japan

0120 191014 or +81 3 5437 9125

support.japan
@freescale.com


Asia/Pacific:

Freescale Semiconductor Hong Kong Ltd.

Technical Information Center

2 Dai King Street

Tai Po Industrial Estate

Tai Po, N.T., Hong Kong

+800 2666 8080

support.asia@freescale.com


For Literature Requests Only:

Freescale Semicond
uctor Literature Distribution
Center

P.O. Box 5405

Denver, Colorado 80217

1
-
800
-
441
-
2447 or 303
-
675
-
2140

Fax: 303
-
675
-
2150

LDCForFreescaleSemiconductor@hibbertgroup.c
om



Information in this document is provided solely to enable system and software
impleme
nters to use Freescale Semiconductor products. There are no express or
implied copyright license granted hereunder to design or fabricate any integrated
circuits or integrated circuits based on the information in this document.

Freescale Semiconductor rese
rves the right to make changes without further notice to
any products herein. Freescale Semiconductor makes no warranty, representation or
guarantee regarding the suitability of its products for any particular purpose, nor does
Freescale Semiconductor assu
me any liability arising out of the application or use of
any product or circuit, and specifically disclaims any and all liability, including without
limitation consequential or incidental damages. “Typical” parameters which may be
pro癩ded⁩ ⁆ree獣sle⁓e
m楣indu捴or da瑡⁳hee瑳tand⽯r⁳pe捩晩捡瑩on猠捡n⁡nd⁤o
癡ry⁩n⁤i晦eren琠app汩ca瑩on猠and⁡c瑵al⁰er景rmanceay⁶aryver 瑩te⸠A汬 opera瑩tg
parameters, including “Typicals” must be validated for each customer application by
customer’s technical expert
献scree獣sle⁓em楣indu捴cr⁤oeso琠convey⁡ny楣敮se
under⁩瑳tpaten琠r楧h瑳tnor⁴he⁲igh瑳to映o瑨er献⁆ree獣sle⁓em楣indu捴or produ捴猠are
no琠de獩gnedI⁩ tendedⰠor⁡u瑨ori穥d for u獥 a猠somponen瑳tin⁳ys瑥m猠楮瑥nded⁦or
獵rgi捡氠業plan琠into⁴he body
Ⱐor o瑨er app汩ca瑩tn猠sn瑥nded 瑯⁳uppor琠or⁳u獴a楮i汩feⰠ
or⁦or any other⁡pp汩ca瑩tn⁩ wh楣h⁴he⁦a楬ure o映the cree獣sle⁓em楣indu捴or
produc琠捯u汤l捲eate⁡ 獩瑵a瑩tn 睨wre persona氠楮lury or⁤eathay o捣ur⸠phou汤
Buyer⁰urchaser⁵se cree獣a汥l
pem楣潮du捴or produ捴猠景r⁡ny⁳u捨 unin瑥ndedr
unau瑨ori穥d⁡pp汩捡瑩tnⰠBuyer 獨a汬⁩ demn楦y and⁨o汤⁆ree獣sle⁓em楣indu捴cr
and⁩瑳 o晦楣er猬⁥mp汯yee猬ssub獩d楡r楥猬sa晦楬ia瑥猬sand⁤楳ir楢u瑯r猠harm汥獳⁡ga楮i琠
a汬⁣污業猬sco獴sⰠdamage猬sand⁥硰e
nse猬sand⁲easonab汥la瑴orney 晥e猠sr楳ingu琠
o昬 d楲e捴cy or⁩nd楲e捴cyI⁡ny⁣ a業映per獯na氠ln橵jyr⁤eath⁡獳s捩a瑥d w楴h⁳u捨
un楮瑥ndedr⁵nau瑨ori穥d⁵seⰠe癥n⁩映獵ch⁣污業 a汬ege猠sha琠cree獣a汥l
pem楣潮du捴or 睡猠neg汩gen琠regard楮g⁴he⁤e獩sn

oranufa捴uref⁴he⁰art.