Esd Module-3 Updated
Esd Module-3 Updated
DESIGN
MODULE-3
EMBEDDED HARDWARE
DESIGN
This Process involves many steps but the main three distinct steps of
this process are:
1. Object file: Each of the source files must be compiled or assembled into an
object file.
2. Relocatable program: All of the object files that result from the first step
must be linked together to produce a single object file, called the
relocatable program.
3. Relocation: Physical memory addresses must be assigned to the relative
offsets within the relocatable program in a process called relocation.
MODULE- BECE403E - EMBEDDED SYSTEM 5
EMBEDDED SYSTEM BUILD PROCESS
EMBEDDED SOFTWARE PROGRAMMING LANGUAGES
To develop software for a General Purpose Computer
Create source file
Type in C code
Build: compile and link
Execute: load and run
To develop software for an embedded system
Create source file
Compiler: translate into assembly program
Assembler: translates the assembly program into machine
code i.e object file
Linker: combine all object files and libraries, resolve all symbols
Locater: assign memory addresses to code and data
Download: copy executable image into Target processor memory
Execute: reset Target processor
MODULE- BECE403E - EMBEDDED SYSTEM 6
EMBEDDED SYSTEM BUILD PROCESS
The pre-processor provides the ability for the inclusion of header files,
macro expansions, conditional compilation, and line control.
Each processor has its own unique machine language, so you need to
choose a compiler that produces programs for your specific target
processor.
Types of Compiler:
⁃ Native-compiler: Runs on a computer platform (x86) and produces code for same
computer platform (x86)
⁃ Cross-Compiler: Runs on one computer platform (x86) and produces code for
different architecture (ARM) BECE403E - EMBEDDED SYSTEM
MODULE- 9
EMBEDDED SYSTEM BUILD PROCESS
COMPILER
A compiler operates in logically interrelated phases whereby source
code is translated assembly file. List of phases includes,
Lexical Analysis: High level program is converted into a sequence of tokens. A
token may be a keyword (while’), an operator (*), an identifier (variable name),
literal (10 or “my string”), comment.
Syntax Analysis: Ensures that tokens are organised in the correct way, according
to the rules of the language otherwise compiler will produce a syntax error.
Semantic analysis: Checks on the logical structure of the program to detect
potential problems such as unused variables, uninitialized variables, etc.
Intermediate code generation: Intermediate representation of the final machine
code is produced.
Code optimization: Code is optimized in order to run faster and efficiently by
performing inline expansion of functions, dead code removal, loop unrolling,
register allocation, etc.
Code generation: The optimized intermediate code is translated into assembly
MODULE- BECE403E - EMBEDDED SYSTEM 10
EMBEDDED SYSTEM BUILD PROCESS
COMPILER – Memory Allocation
After the code generation is finished, the compiler allocates memory
for code and data in sections; each section has different information.
Stack and Heap segments are not allocated by the compiler but by the
MODULE- BECE403E - EMBEDDED SYSTEM 11
EMBEDDED SYSTEM BUILD PROCESS
COMPILER – Memory Allocation Example
.bss
.data
.rodata
.text
.stack
.heap
Each processor has its own unique machine language, so you need to
choose a appropriate assembler that produces programs for your
specific target processor.
Note that the object file only contains the sections for static variables.
At this stage, section locations are not fixed.
While combining the object files together, the linker performs the
following operations:
1. Symbol resolution:
In multi-file program, if there are any references to symbol defined in another
file, the assembler marks these references as “unresolved”.
The linker determines the values of these references from other object files or
all specified library/archive (.a) files, and patches the code with the correct
values.
If, the Linker still cannot resolve a symbol it will report an ‘unresolved
MODULE- reference’ error. BECE403E - EMBEDDED SYSTEM 16
EMBEDDED SYSTEM BUILD PROCESS
LINKER
2. Relocation: Process of changing addresses already assigned to symbols. This will
also involve patching up all references to reflect the newly assigned address.
Relocation process involves following,
a) Section Merging: The Linker then concatenates like-named sections from all
the input object files. The combined sections (output sections) are usually
given the same names as their input sections. Program addresses are
adjusted to take account of the concatenation.
b) Section placement: When a program is assembled each section is assumed to
start from address 0. And thus, symbols are assigned values relative to the
start of the section. When the final executable is created, the section is placed
at some address X. And all references to the symbols defined within the
section, are incremented by X, so that they point to the new location.
c) Data initialisation: Create a shadow data section (.sdata) to copy read-only
sections (.code) to RAM to speed up execution
After merging all of the code and data sections and resolving all of the
MODULE- BECE403E - EMBEDDED SYSTEM 17
EMBEDDED SYSTEM BUILD PROCESS
LOCATOR
A locator performs the conversion from relocatable program to
executable binary image.
The locator gets the output file of the linker and maps the code and
data into microcontroller memory by assigning physical addresses to
code and data.
The locator will perform checks to ensure that your code and data
sections will fit into the designated regions of memory.
Linker Control File (LCF) also another name for this file is linker-script
file, linker configuration file is responsible to inform the locator how to
map the executable into proper addresses.
The ELF file is also used by the debugger when performing source-code
debugging.
In order to be loaded onto the target the ELF file must be converted
into a native flash / PROM format (typically, .bin or .hex)
The output of this final step of the build process is a binary image
containing physical addresses for the specific embedded system.
Makefiles are associated with the "make" build automation tool, which
reads the instructions from the Makefile and executes the necessary
commands to build the project.
It can generate machine code for various ARM processors, from Cortex-
M microcontrollers to more powerful Cortex-A application processors.
GCC Features:
Cross-Compilation: GCC allows cross-compilation, enabling developers to compile
code on one architecture (e.g., x86) for execution on a different architecture (e.g.,
ARM).
Optimization: GCC provides various optimization levels to improve code
performance and size.
Debugging: It integrates with debuggers like GDB for source-level debugging.
Wide Language Support: GCC supports multiple programming languages,
MODULE- providing flexibility in language choices
BECE403E for embedded
- EMBEDDED SYSTEM development. 25
COMPILER TOOLCHAIN
ARM TOOLCHAIN
ARM provides a comprehensive toolchain for developing software for
ARM-based processors.
This toolchain includes not only a compiler but also other essential
tools for linking, assembling, and debugging.
Middleware can also provide services for data storage, security, and
fault tolerance.
Device drivers are often more specific than the HAL and they are
designed to interface with specific hardware, such as a network
adapter, graphics card, or storage device.
36
Keil μVision IDE IAR Embedded Workbench STM32 Cube IDE MPLAB X IDE
The program
MODULE- runningBECE403E
on the host of
- EMBEDDED a ICD has a user interface42
SYSTEM
DEBUGGING TOOLS
IN-CIRCUIT DEBUGGER (ICD)
Using ICD, the programmer can perform the following,
Start/restart/kill, and stepping through program.
Set Software breakpoints.
Reading/writing registers or data at specified address.
It contains a copy of target processor, plus RAM, ROM, and its own
embedded software.
This tool is needed to analyse performance of the code and to see how
the code will work in the real-time environment.
Logic analyser
setup
Software interface for the Discovery series logic analyser from Prodigy
MODULE- Technovations
BECE403E - EMBEDDED SYSTEM 52
DEBUGGING TOOLS
LOGIC ANALYZER