Es Unit - 5 Embedded System Development
Es Unit - 5 Embedded System Development
Es Unit - 5 Embedded System Development
IDEs used in embedded firmware development are slightly different from the
generic IDEs used for high level language based development for desktop applications. In embedded
applications, the IDE is either supplied by the target processor/controller manufacturer or by third
party vendors or as open source. MPLAB is an IDE tool supplied by microchip for developing
embedded firmware using their PIC family of microcontrollers. Keil µVision3 (spelt as micro vision
three) from Keil software is an example for a third party IDE, which is used for developing embedded
firmware for 8051 family microcontrollers. Code Warrior by Metrowerks is an example of IDE for
ARM family of processors. It should be noted that in embedded firmware development applications
each IDE is designed for a specific family of controllers/processors and it may not be possible to
develop firmware for all family of controllers/processors using a single IDE (as of now there is no
known IDE with support for all family of processors/controllers). However there is a rapid move
happening towards the open source IDE, Eclipse for embedded development. Most of the
processor/control manufacturers and third party IDE providers are trying to build the IDE around the
popular Eclipse open source IDE. This may lead to a single IDE based on Eclipse for embedded
system development in the near future. Since this book is primarily focusing on 8051 based
embedded firmware development, the IDE chosen for demonstration is Keil µ Vision3. A demo
version of the tool for Microsoft Windows OS based development is available for free download from
the Keil Software website. Please install the same on your machine before proceeding to the next
sections.
7.1.1 THE KEIL µ VISION3 IDE FOR 8051
Keil µ Vision3 is a licensed IDE tool from Keil Software (www.keil.com), an ARM
company, for 8051 family microcontroller based embedded firmware development. To start with the
IDE (after installing the demo tool) execute the program Uv3.exe (ir the short cut ‘Keil µ Vision3’
from desktop or ‘All programs’ tab from ‘Start Menu’ – For Host machine with Microsoft® Window
Operating System). The IDE view is shown in Fig. 7.1.2.
The IDE looks very similar to the Microsoft® Visual Studio IDE and it contains
various menu options, a project window showing files, Register view, Books and Function Tab and
an output window. To start a new project, go to the ‘Project’ tab on the menu, select ‘New Project’
Pop-up dialog Box (Let it be ‘sample’). Choose the directory to save the project from the pop-up
dialog. The default extension of a project workspace file is .uv2. On clicking the ‘Save’ button of the
‘Create New Project’ pop-up dialog, a device selection dialog as shown in Fig. 7.1.3 appears on the
screen.
This Dialog Box lists out all the vendors (manufacturers) for 8051 family
microcontroller, supported by IDE. Choose the manufacturer of the chip for your design (Let it be
‘Atmel’ for our design). Atmel itself manufacturers a variety of 8051 flavours. Choose the exact part
number of the device used as the
Fig 7.1.2 Keil µ Vision3 Integrated Development Environment (IDE)
Once the target processor is selected, the IDE automatically adds the required startup code for
the firmware and it prompts you whether the standard startup code needs to be added to the project
(Fig. 7.1.5). Press ‘Yes’ to proceed. The startup code contains the required default initialization like
stack pointer setting and initialization, memory clearing, etc, On cross-compiling, the code generated
for the startup file is placed on top of the code generated for the function main(). Hence the reset
vector
Fig 7.1.5 Startup file addition to the project
(0000H) always starts with the execution of startup code before the main code. For more details in the
contents and code of startup file please go through the µ Vision help files which is listed under the
‘Books’ section of the project workspace window.
A ‘Target’ group with the name ‘Target 1’ is automatically generated under the ‘Files’
section of the project Window. ‘Target 1’ contains a ‘Source Group’ with the name ‘Source Group 1’
and the startup file (STARTUP.A51) is kept under this group (Fig.7.1.6). All these groups are
generated automatically. If you want you can rename these groups by clicking the respective group
names.
The code is written in the text editor which appears within the IDE on selecting the
‘New’ tab from the ‘File’ Menu. Write the code in C language syntax (Fig. 7.1.7). Add the necessary
header files. You can make use of the standard template files available under the ‘Templates’ tab of
the ‘Project Window’ for adding functions, loops, conditional instructions, etc. for writing the code.
Once you are done with the code, save it with extension c in a desired folder (Preferably in the current
project directory). Let the name of the file be ‘sample.c’. At the moment you save the program with
extension .c, all the keywords (like #include, int, void, etc.) appear in a different colour and the title
bar of the IDE displays the name of the current .c file along with its path. By now we have created a
‘c’ source file. Next step is adding the created source file to the project. For this, right click on the
‘Source Group’ from the ‘Project Window’ and select the option ‘Add Files to Group ‘Source
Group”. Choose the file ‘sample.c’ from the file selection Dialog Box and press ‘Add’ button and exit
the file selection dialog by pressing ‘Close’ button. Now the file is added to the target project (Fig.
7.1.8). You can see the file in the ‘Project Window’ under ‘Files’ tab beneath the ‘Source Group’.
If you are following the modular programming technique, you may have different
source files for performing an intended operation. Add all those files to the project as described
above. It should be noted that function main() is the only entry point and only one ‘.c’ file among the
files added to the project is allowed to contain the function main(). If more than one file contains a
function with the name main(), compilation will end up in error. The next step is configuring the
target. To configure the target, go to ‘Project’ tab on the Menu and select ‘Options for Target’. The
configuration widow as shown in Fig. 7.1.9 is displayed.
Fig 7.1.9 Target Configuration
The target configuration window is a tabbed dialog box. The device is already
configured at the time of creating a new project by selecting the target device (e.g. Atmel AT89C51).
If you want to check it, select the ‘Device’ tab and verify the same. Select ‘Target’ tab and configure
the following. Give the clock frequency for which the system is designed. E.g. 6MHz, 11.0592MHz,
12MHz, 24MHz, etc. This has nothing to do with the firmware creation but it is very essential while
debugging the firmware to note the execution time since execution time is dependent on the clock
frequency. If the system is designed to make use of the processor resident code memory, select the
option Use On-chip ROM (For AT89C51 On-chip ROM is 4K only; 0x0000 to 0x0FFF). If external
code memory is used, enter the start address and size of the code memory at the Off-chip code
memory column (e.g. Eprom start: 0x0000 and size 0x0FFF). The working memory (data memory or
RAM) can also be either internal or external to the processor. If it is external, enter the memory map
starting address of the external memory along with the size of external memory in the Off-chip X data
memory section (e.g. Ram start: 0x8000 and size 0x1000). Select the memory model for the target.
Memory model refers to the data memory. Keil supports three types of data memory model; internal
data memory (Small), external data memory in paged mode (Compact) and external data memory in
non-paged mode (Large). Now select the Code memory size. Code memory model is also classified
into three; namely, small (code less than 2K bytes), Compact (2K bytes functions and 64K bytes code
memory) and Large (Plain 64K bytes memory). Choose the type depending on your target application
and target hardware design. If your design is for an RTOS based system, select the supported RTOS
by the IDE. Keil supports two 8 bit RTOS namely, RTX51 Tiny and RTX51 Full. Choose none for a
non RTOS based design.
Move to the next Tab, ‘Output’. The output tab holds the setting for output file generation
from the source code (Fig. 7.1.10). the source file can either be converted into an executable machine
code or a library file.
‘C51’ tab settings are used for cross compiler directives and settings like/Pre-
processor symbols, code optimization settings, type of optimization (viz. code optimized for
execution speed and code optimized for size), include file’s path settings, etc. The ‘A51’ tab settings
are used for assembler directives and settings like conditional assembly control symbols, include
file’s path settings etc. Another important option is ‘Debug’. The ‘Debug’ tab is used for configuring
the firmware debugging. ‘Debug’ supports both simulation type firmware debugging and debugging
the application while it is running on the target hardware (Fig. 7.1.12).
You can either select the Simulator based firmware debugging or a target firmware
level debugging from the ‘Debug’ option. If the Simulator is selected, the firmware need not be
downloaded into the target machine. The IDE provides an application firmware debugging
environment by simulating the target hardware in a software environment. It is most suitable for
offline analysis and rapid code developments. If target level debugging is selected, the binary file
created by the cross-compilation process needs to be downloaded into the target hardware and the
debugging is done by single stepping the firmware. A physical link should be established between the
target hardware and PC on which the IDE is running for target level debugging. Target level hardware
debugging is achieved using the Keil supported monitor programs or through an emulator interface.
Select the same from the Drop-down list. Normally the link between target hardware and IDE is
established through a Serial interface. Select the ‘Comm Port’ to which the target device is connected
and the baudrate for communication (Fig. 7.1.13).
If the Debug mode is configured to use the target level debugging using any one of
the monitor program or the emulator interface supported by the Keil IDE, the created binary file is
downloaded into
the target board using the configured serial connection and the firmware execution occurs in real
time. The firmware is single stepped (Executing instruction-by-instruction) within the target
processor and the monitor program running on the target device reflects the various register and
memory contents in the IDE using the serial interface.
The ‘Utilities’ tab is used for configuring the flash memory programming of the
target processor/controllers from the Keil IDE (Fig. 7.1.14). You can use either Keil IDE supported
programming drivers or a third party tool for programming the target system’s FLASH memory. For
making use of Keil IDE provided flash memory programming drivers, select the option ‘Use Target
Driver for Flash Programming’ and choose a driver from the drop-down list. To use third party
programming tools, select the option ‘Use External Tool for Flash Programming’ and specify the
third party tool to be used by giving the path in the ‘Command’ column and specify the arguments (if
any) in the ‘Arguments’ tab to invoke the third party application.
With this we are done with the writing of our first simple Embedded C program and
configuring the target controller for running it. The next step is the conversion of the firmware written
in Embedded C to machine language corresponding to the target processor/controller. This step is
called cross-compilation. Go to ‘Project’ tab in the menu and select ‘Rebuild all target files’. This
cross-compiles all the files within the target group (for modular programs there may be multiple
source files) and link the object codes created by each file to generate the final binary. The output of
cross-compilation for the ‘Hello World’ application is giving in Fig. 7.1.15.
Fig 7.1.15 Conversion of the Embedded C program to 8051 Machine code
You can see the cross-compilation step & linking in the o/p window along with
cross-compilation error history. Now perform a ‘Build Target’ operation. This links all the object files
created (in a multi-file system where each source files are cross-compiled separately) (Fig. 7.1.16).
In a multi source file project (source group containing multiple .c files) each file can
be separately cross-compiled by selecting the ‘Translate current file’ option. This is known as
Selective Compilation. Remember this generates the object file for the current file only and it needs to
be combined with object files generated for other files, by using ‘Build Target’ option for creating the
final executable (Fig. 7.1.17). selective compilation is very helpful in a multi file project where a
modified file only needs to be re-compiled and it saves the time in re-compiling all the files present in
the target group.
7.2 TYPES OF FILES GENERATED ON CROSS-COMPILATION
Cross-Compilation is the process of converting a source code written in high level language
(like ‘Embedded C’) to a target process or controller understandable machine code (ex: ARM
processor or 8051 microcontroller specific machine code). The conversion of the code is done by
software running on a processor / controller (ex: x86 processor based pc) which is different from the
target processor. The software performing this operation is referred as the ‘Cross-compiler’. Cross
assembling is similar to Cross-compiling; the only difference is that the code written in a target
processor / controller specific Assembly code is converted into its corresponding machine code. The
application converting Assembling instruction to target processor / controller specific machine code is
known as Cross-assembler. Cross-compilation / Cross-Assembling is carried out in different steps and
the process generated various types of intermediate files. Various files generated during the cross-
compilation / cross-assembling process are:
List File (.lst), Hex File(.hex), pre-processor out put file, Map file (File extension linker dependent),
Object file (.obj).
Source Code:
The Source code listing outputs the line number as well as the source code on that
line. Specific cross compiler directive can be used to include or exclude the conditional codes (code
in # if blocks) in the source code listings.
Void main ( )
{
Printf (“Hello world!\n)
}
Assembly listing:
Assembly listing contains the assembly code generated by the cross compiler for the
‘C’ source code. Assembly code generated can be excluded from the list file by using special
compiler directives.
Firm ware debugging is preformed to figure the bug or the error in the
firmware which creates the unexpected behavior. Firmware is analogous to the human body in the
sense it is wide spread and / or modular. During the early days of embedded system development,
there were no debug tools available and only ways was “Burn the code in an EEPROM”.
This is the most primitive type of firmware debugging technique where the
code is separated into different functional code units. Instead of burning the entire code into the
EEPROM chip at once, the code is burned in incremental order, where the code corresponding to all
functionalities are separately codes, cross compiled and burned into the chip one bye one.
If the first functionality is found working perfectly on the target board with
the corresponding code burned into the EEPROM, go for working perfectly burning the code
corresponding to the next functionality and check whether it is working. Repeat this process till all
functionalities are covered.
All the functionalities working properly, combine the entire source for all
functionalities together, re-compile and burn the code for the total system functioning.
The most common type of interface used b/w target board and debug
application is Rs-232c serial interface. After the successful completion of the ‘Monitor program’
development it is compiled and burned into the flash memory or ROM of the target board. The code
memory containing the monitor program is known as ‘monitor Rom’.
The monitor program contains the following set of minimal features.
Command set interface to establish communication with the debugging application.
Firm ware down load option to code memory.
Examine and modify processor registers and working memory (RAM)
Single step program execution.
Set break point in firmware execution.
Send debug information to debug application running on most machine.
Emulation Memory:
It is the Random Access Memory (RAM) incorporated in the
Emulator device. It acts as a replacement to the target board’s EEPROM where the code is supposed
to be downloaded after each firmware modification. Hence the original EEPROM memory is
emulated by the RAM of emulator. This is known as ‘ROM Emulation’.
Multi meter:
Multi meter is used for measuring various electrical quantities like voltage (Both Ac
and DC), current (DC as well as AC) resistance, capacitance, continuity checking, transistor
checking, cathode and mode identification of diode. In embedded hardware debugging it is mainly
used for checking the circuit continuity between different points on the board measuring the supply
voltage, checking the signal value, polarity etc. the digital version is preferred over analog the one for
various reasons like readability, accuracy, etc..
Digital CRO:
CRO is a little more sophisticated tool compared to a multimeter. CRO is used for
wave from capturing and analysis, measurement of signal strength. CRO is very good tool I analyzing
interference noise in the power supply line and other signal lines. Monitoring the crystal oscillator
signal from target board is a typical example of the usage of CRO for waveform capturing and
analysis in target board is a typical example of the usage of CRO for ware form capturing and
analysis in target board debugging. CRO’s are available in both analog and digital versions. Though
digital CRO are costly and are best suited for forget board debugging applications. Modern digital
CRO’s more than one channel and it is easy to capture and analyses various signals channel and it is
easy to capture and analyze various signals from the target board using multiple channels
simultaneously.
Logic Analyzer:
A logic analyzer is the big brother of digital CRO Logic analyzer is used for
capturing digital data (logic 1 and 0) from a digital circuitry where as CRO is employed in capturing
all kinds of waves including logic signals. Another major limitation of CRO is that the total number
of logic signals / wave forms that can be captured with a CRO is a limited to the number of channels.
A logic analyzer contains special connectors and clips which can be attached to the target board for
capturing digital data. In target board debugging applications a logic analyzer captures the states of
various port pins, address bus and data bus to the target processor / controller. Most modern logic
analyzers contain provisions for storing captured data selecting a desired region of the captured ware
form, zooming selected region of the captured ware form.
Function Generator:
Function generator is not a debugging tool. It is an input signal simulator
tool. A function generator is capable of producing various periodic wave forms like sine wave, square
wave, saw tooth wave, etc., with different frequencies and amplitude. The target board may require
some kind of periodic waveform with a particular frequency as input to some part of the board. This
in a debugging environment the function generator serves the purpose of generating and supplying
required signals.