SlideShare ist ein Scribd-Unternehmen logo
1 von 76
Downloaden Sie, um offline zu lesen
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Embedded System
PART 9(C Programming)
1
ENG.KEROLES SHENOUDA
Embedded C (Cont.)
Learn in Depth
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Download QEMU
 Download Qemu
 https://qemu.weilnetz.de/w32/qemu-w32-setup-20180430.exe
2
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
3
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Download GNU ARM toolchain
 https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
4
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
5
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
What is QEMU ?
 QEMU (short for "Quick EMUlator") is a free and open-source machine
emulator and virtualizer written originally by Fabrice Bellard
 Can emulate 80386, 80486, Pentium, Pentium Pro, AMD64 – from x86
architecture
 PowerPC, ARM, MIPS, SPARC, SPARC64
 Work on FreeBSD, FreeDOS, Linux, Windows 9x, Windows 2000, Mac OS X,
QNX, Android
6
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
List of supported CPUs (ARM)
7
 Available CPUs:
 arm1026
 arm1136
 arm1136-r2
 arm1176
 arm11mpcore
 arm926
 arm946
 cortex-a15
 cortex-a8
 cortex-a9
 cortex-m3
 pxa250
 pxa255
 pxa260
 pxa261
 pxa262
 pxa270-a0
 pxa270-a1
 pxa270
 pxa270-b0
 pxa270-b1
 pxa270-c0
 pxa270-c5
 sa1100
 sa1110
 ti925t
 any
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
List of Platforms
(ARM)
8
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
QEMU Project
“QEMU does not have a high level design description document - only the source
code tells the full story”
9
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Volatile Type Qualifier
10
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Syntax of C's volatile Keyword
 declare a variable volatile, include the keyword volatile before
or after the data type in the variable definition. For instance
both of these declarations will declare foo to be a volatile
integer:
 volatile int foo;
 int volatile foo;
11
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
volatile
 Now, it turns out that pointers to volatile variables are
very common, especially with memory-mapped I/O
registers. Both of these declarations declare pReg to be
a pointer to a volatile unsigned 8-bit integer:
volatile uint8_t * pReg;
uint8_t volatile * pReg;
12
pointer to a volatile unsigned 8-bit integer
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
volatile
 Volatile pointers to non-volatile data
int * volatile p;
13
Volatile pointers to non-volatile data
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
volatile
 a volatile pointer to a volatile variable:
int volatile * volatile p;
14
volatile pointer to a volatile variable
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Proper Use of C's volatile Keyword
 Memory-mapped peripheral registers
 Global variables modified by an interrupt service routine
 Global variables accessed by multiple tasks within a
multi-threaded application
15
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Peripheral Registers
 Embedded systems contain real hardware, usually with
sophisticated peripherals. These peripherals contain registers
whose values may change asynchronously to the program flow.
As a very simple example, consider an 8-bit status register that is
memory mapped at address 0x1234. It is required that you poll
the status register until it becomes non-zero.
16
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
incorrect implementation
17
uint8_t * pReg = (uint8_t *) 0x1234;
// Wait for register to become non-
//zero while
(*pReg == 0) { } // Do something else
This will almost certainly fail as soon as you turn
compiler optimization on, since the compiler will
generate assembly language that looks something
like this:
mov ptr, #0x1234
mov a, @ptr
loop:
bz loop
assembly
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
To force the compiler to do what we
want, we modify the declaration to:
18
uint8_t volatile * pReg = (uint8_t volatile *) 0x1234;
//The assembly language now looks like this:
mov ptr, #0x1234
loop:
mov a, @ptr
bz loop
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Interrupt Service Routines
19
int etx_rcvd = FALSE;
void main()
{
...
while (!ext_rcvd)
{
// Wait
}
...
}
//Interrupt
void rx_isr(void)
{
...
if (ETX == rx_char)
{
etx_rcvd = TRUE;
}
...
}
The solution is to declare the
variable etx_rcvd to be volatile
Optimization cause issue
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Multithreaded Applications
20
int cntr;
void task1(void)
{
cntr = 0;
while (cntr == 0)
{
sleep(1);
}
...
}
void task2(void)
{
...
cntr++;
sleep(10);
...
}
This code will likely fail once the
compiler's optimizer is enabled.
Declaring cntr to be volatile is the
proper way to solve the problem.
Optimization cause issue
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Defining Types
 The typedef keyword
 defines a new type.
 typedef signed char int8_t;
 typedef unsigned char uint8_t;
 typedef volatile signed char vint8_t;
 typedef volatile unsigned char vuint8_t;
 typedef signed short int16_t;
 typedef unsigned short uint16_t;
21
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Now lets see how access the
register absolute address
22
Write 0xFFFFFFFF on SIU register which have absolute
address 0x30610000
PORTAPORTBPORTCPORTD
1B
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Solution 1
 Declare a pointer,
 volatile int *p;
 Assign the address of the I/O memory location to the pointer,
 p = (volatile int*) 0x30610000;
/* 4-byte long, address of some memory-mapped register */
 Output a 32-bit value
 *p = 0xFFFFFFFF;
23
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Solution 2
 *((volatile unsigned long*)(0x306100)) = 0xFFFFFFFF;
 Or
 #define MYREGISTER *((volatile unsigned long*)(0x306100))
24
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Solution 3
25
union {
vuint32_t ALL_ports;
struct {
vuint32_t PORTA:8 ;
vuint32_t PORTB:8 ;
vuint32_t PORTC:8 ;
vuint32_t PORTD:8 ;
} SIU_fields;
} SIU_R;
volatile SIU_R* PORTS = (volatile SIU_R* ) 0x306100 ; /*Address*/
PORTS ->ALL_ports =0xFFFFFFFF; // access all BITS
PORTS ->SIU_fields.PORTA = 0xFF ;
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
useful references for
C and Embedded C
26
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
27
How To Write
Embedded C Code
From Scratch
without IDE ?
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
You will need
Cross Toolchain
MakefileLinker Script
Startup.s
C Code files
28
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
C Startup
 It is not possible to directly execute C code, when the processor comes out of
reset. Since, unlike assembly language, C programs need some
basic pre-requisites to be satisfied. This section will describe the
pre-requisites and how to meet the pre-requisites.
 We will take the example of C program that calculates the sum of an array as
an example.
 And by the end of this section, we will be able to perform the necessary
setup, transfer control to the C code and execute it.
29
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
C Startup
 a small block of assembly language code that prepares the way for the execution of software written
in a high-level language.
 Startup code for C programs usually consists of the following series of actions:
 Disable all interrupts.
 Copy any initialized data from ROM to RAM.
 Zero the uninitialized data area.
 Allocate space for and initialize the stack.
 Initialize the processor’s stack pointer.
 Create and initialize the heap
 Enable interrupts.
 Call main.
 the startup code will also include a few instructions after the call to main. These instructions will be executed only
in the event that the high-level language program exits (i.e., the call to main returns).
30
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
31
Sum of Array in C
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_systemBefore transferring control to C code, the
following have to be setup correctly.
 Stack (r13”SP”)
 Global variables
Initialized .data
Uninitialized .bss
 Read-only data .rodata
 Then force the PC register
to jump on the main functions
32
CPU Memory
Peripherals/Modules
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Stack
 C uses the stack for storing local (auto)
variables, passing function arguments,
storing return address, etc. So it is essential
that the stack be setup correctly, before
transferring control to C code.
 Stacks are highly flexible in the ARM
architecture, since the implementation is
completely left to the software.
33
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Stack
34
 So all that has to be done in the startup code is to point (r13”SP”) register
at the highest RAM address, so that the stack can grow downwards (towards
lower addresses). For the connex board this can be achieved using the
following ARM instruction.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Global Variables
 When C code is compiled, the compiler places initialized global variables in the .data
section. So just as with the assembly, the .data has to be copied from Flash to RAM.
 The C language guarantees that all uninitialized global variables will be initialized to zero.
When C programs are compiled, a separate section called .bss is used for uninitialized
variables. Since the value of these variables are all zeroes to start with, they do not have
to be stored in Flash. Before transferring control to C code, the memory locations
corresponding to these variables have to be initialized to zero.
35
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Read-only Data
 GCC places global variables marked as const in a separate section, called
.rodata. The .rodata is also used for storing string constants.
 Since contents of .rodata section will not be modified, they can be placed in
Flash. The linker script has to modified to accomodate this.
36
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
37
Section Placement
“Very important”
Learn in depth
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Linker Script for C code 38
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
The startup code has the following parts 39
 exception vectors
 code to copy the .datafrom Flash to RAM
 code to copy zero out the .bss
 code to setup the stack pointer
 branch to main
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Startup Assembly 40
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Labs
41
HELLO WORLD FOR BARE METAL
On VersatilePB platform, that contains an
ARM926EJ-S core
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Prerequisites
 Download:
Qemufrom https://qemu.weilnetz.de/w32/
 GNU ARM Embedded Toolchain from
 developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
 THEN INSTALL THEM
42
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
43
What is QEMU ?
− QEMU (short for "Quick EMUlator") is a free and open-source machine
emulator and virtualizer written originally by Fabrice Bellard
− Can emulate 80386, 80486, Pentium, Pentium Pro, AMD64 – from x86
architecture
− PowerPC, ARM, MIPS, SPARC, SPARC64
− Work on FreeBSD, FreeDOS, Linux, Windows 9x, Windows 2000, Mac
OS X, QNX, Android
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
44
− Available CPUs:
− arm1026
− arm1136
− arm1136-r2
− arm1176
− arm11mpcore
− arm926
− arm946
− cortex-a15
− cortex-a8
− cortex-a9
− cortex-m3
− pxa250
− pxa255
− pxa260
− pxa261
− pxa262
− pxa270-a0
− pxa270-a1
− pxa270
− pxa270-b0
− pxa270-b1
− pxa270-c0
− pxa270-c5
− sa1100
− sa1110
− ti925t
− any
List of supported CPUs (ARM)
$ qemu-system-arm –cpu ?
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
45
List of
Platforms
(ARM)
$ qemu-system-arm -machine ?
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
46
QEMU Project
“QEMU does not have a high level design description document - only the source code tells
the full story”
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
ARM system emulated with QEMU
 qemu-system-arm is the software that emulates a VersatilePB platform
For more information “VersatilePB physical Board’
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dsi0034a/index.html
 http://www.arm.com/products/tools/development-boards/versatile-express
 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0224i/index.html
47
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
HELLO WORLD FOR BARE METAL
48
tx RX
You will need
Cross Toolchain
Makefile
Linker Script .ld
C Code files
Startup.s
Exectuable File
Test.bin
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Lab: Steps
 The QEMU emulator supports the VersatilePB platform, that contains an ARM926EJ-S
core and, among
 other peripherals, four UART serial ports;
 the first serial port in particular (UART0) works as a terminal
 when using the -nographic or “-serial stdio” qemu option. The memory map of the
VersatilePB board is implemented in QEMU in this board-specific C source;
 note the address where the UART0 is mapped: 0x101f1000.
49
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
50there is a register
(UARTDR) that
is used to transmit
(when writing in the
register) and receive
(when reading) bytes;
this register is
placed
at offset 0x0, so you
need to read and write
at the beginning of the
memory allocated for
the UART0
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Lab: Steps
 The QEMU emulator supports the VersatilePB platform, that contains an ARM926EJ-S
core and, among
 other peripherals, four UART serial ports;
 the first serial port in particular (UART0) works as a terminal
 when using the -nographic or “-serial stdio” qemu option. The memory map of the
VersatilePB board is implemented in QEMU in this board-specific C source;
 note the address where the UART0 is mapped: 0x101f1000.
51
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
To implement the simple “Hello world!”
printing, you should write this test.c file:
52
volatile unsigned int * const UART0DR = (unsigned int *)0x101f1000;
void print_uart0(const char *s) {
while(*s != '0') { /* Loop until end of string */
*UART0DR = (unsigned int)(*s); /* Transmit char */
s++; /* Next char */
}
}
void c_entry() {
print_uart0("Hello world!n");
}
• The volatile keyword is necessary to instruct the compiler that the memory
pointed by UART0DR can
change or has effects independently of the program.
• The unsigned int type enforces 32-bits read and write access.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
startup.s
53
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
the linker script test.ld 54
ENTRY(_Reset)
SECTIONS
{
. = 0x10000;
.startup . : { startup.o(.text) }
.text : { *(.text) }
.data : { *(.data) }
.bss : { *(.bss COMMON) }
. = ALIGN(8);
. = . + 0x1000; /* 4kB of stack memory */
stack_top = .;
}
.startup
.text
.data
.bss
Stack_top
0x1000
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
55
Create the binary file
Go to GNU Tools ARM Embedded5.4 2016q3bin directory
And open the CMD Console
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
56Create the binary file
Then run those commands
Generate startup object file
$ arm-none-eabi-as -mcpu=arm926ej-s -g startup.s -o startup.o
Generate test object file
$ arm-none-eabi-gcc -c -mcpu=arm926ej-s -g test.c -o test.o
Invoke the linker and pass the linker script
$ arm-none-eabi-ld -T test.ld test.o startup.o -o test.elf
Generate binary file
$ arm-none-eabi-objcopy -O binary test.elf test.bin
interview
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
To make sure the entry point at address
0x10000 Use the readelf Binary utilities
57
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
58
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
To see the disassembly
Use the odjdump Binary utilities
59
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
60
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
To run the program in the emulator 61
Go to qemu directory
And open the CMD Console
Copy the test.bin on the qemu folder then press this Command
$ qemu-system-arm -M versatilepb -m 128M -nographic -kernel test.bin
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
To Debug the Code
 Using gdb, because QEMU implements a gdb connector using a TCP connection. To do so, run
the emulator with the correct options as follows
$ qemu-system-arm -M versatilepb -m 128M -nographic -s -S -kernel test.bin
 This command freezes the system before executing any guest code, and waits for a connection
on the TCP port 1234.
 From ARM ToolChan terminal, run arm-none-eabi-gdb and enter the commands:
62
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
63
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
64
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
65
GNU Debugger Tutorial
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
A Simple Makefile Tutorial Lab
66
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
A Simple Makefile Tutorial
 Makefiles are a simple way to organize code compilation. This tutorial does
not even scratch the surface of what is possible using make, but is intended
as a starters guide so that you can quickly and easily create your own
makefiles for small to medium-sized projects.
67
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Makefile 1
68
#prebared by Keroles Shenouda (Learn In Depth)
helloworld: test.c
arm-none-eabi-as -mcpu=arm926ej-s -g startup.s -o startup.o
arm-none-eabi-gcc -c -mcpu=arm926ej-s -g test.c -o test.o
arm-none-eabi-ld -T test.ld test.o startup.o -o test.elf
arm-none-eabi-objcopy -O binary test.elf test.bin
If you put this rule into a file called Makefileor makefileand then type makeon the command line it will execute
the compile command as you have written it in the makefile. Note that makewith no arguments executes the first
rule in the file. Furthermore, by putting the list of files on which the command depends on the first line after the :, make knows
that the rule helloworldOne very important thing to note is that there is a tab before the gcc command in the makefile. There
must be a tab at the beginning of any command, and make will not be happy if it's not there.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Makefile 1
69
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Makefile 2
70
defined some constants CC and CFLAGS. It turns out these are special constants that communicate to make how we want to compile the files test.c
In particular, the macro CC is the C compiler to use, and CFLAGS is the list of flags to pass to the compilation command.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Makefile 3
71
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Makefile 4
72
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
Describe deeply the compilation
process
73
Preprocessing It is the first stage of compilation. It
processes preprocessor directives like include-files,
conditional compilation instructions and macros.
Compilation It is the second stage. It takes the output of
the preprocessor with the source code, and generates
assembly source code.
Assembler stage It is the third stage of compilation. It
takes the assembly source code and produces the
corresponding object code.
Linking It is the final stage of compilation. It takes one or
more object files or libraries and linker script as input and
combines them to produce a single executable file. In doing
so, it resolves references to external symbols, assigns final
addresses to procedures/functions and variables, and revises
code and data to reflect new addresses (a process called
relocation).
File.map
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
For example
 perform the three separate tasks (compiling, linking,
and locating) also you can automate the build
procedure with makefiles.
 The compiler will generate the object files
led.o and blink.o. linker performs the linking
and locating of the object files.
 For the third step, locating, there is a linker script
file named viperlite.ld that we input to ld in order to
establish the location of each section
74
The .map file gives a complete listing of all code and data addresses for the final software image. If you
have never seen such a map file before, be sure to take a look at this one before reading on. It provides
information similar to the contents of the linker script described earlier. However, these are results rather
than instructions and therefore include the actual lengths of the sections and the names and locations of the
public symbols found in the relocatable program. We’ll see later how this file can be used as a debugging aid.
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
 linker can be passed to it in the
form of a linker script. Such scripts are
sometimes used to control the exact
order of the code and data sections
within the relocatable program
75
https://www.facebook.com/groups/embedded.system.KS/
Follow us
Press
here
#LEARN_IN DEPTH
#Be_professional_in
embedded_system
References
76
 Freedom Embedded
Balau's technical blog on open hardware, free software and security
 https://balau82.wordpress.com

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
C programming session6
C programming  session6C programming  session6
C programming session6
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Embedded C - Day 1
Embedded C - Day 1Embedded C - Day 1
Embedded C - Day 1
 
Introduction to armv8 aarch64
Introduction to armv8 aarch64Introduction to armv8 aarch64
Introduction to armv8 aarch64
 
Embedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 CourseEmbedded System Programming on ARM Cortex M3 and M4 Course
Embedded System Programming on ARM Cortex M3 and M4 Course
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
Autosar software component
Autosar software componentAutosar software component
Autosar software component
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Bootloaders (U-Boot)
Bootloaders (U-Boot) Bootloaders (U-Boot)
Bootloaders (U-Boot)
 
Advanced C - Part 1
Advanced C - Part 1 Advanced C - Part 1
Advanced C - Part 1
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
IBM Z for the Digital Enterprise - DevOps for Z
IBM Z for the Digital Enterprise - DevOps for Z IBM Z for the Digital Enterprise - DevOps for Z
IBM Z for the Digital Enterprise - DevOps for Z
 
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with DebuggingPART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
PART-3 : Mastering RTOS FreeRTOS and STM32Fx with Debugging
 

Ähnlich wie EMBEDDED C

Instructions 3-5 pages double space research paper about Eric Sc.docx
Instructions 3-5 pages double space research paper about Eric Sc.docxInstructions 3-5 pages double space research paper about Eric Sc.docx
Instructions 3-5 pages double space research paper about Eric Sc.docx
normanibarber20063
 

Ähnlich wie EMBEDDED C (20)

C Condition and Loop part 2.pdf
C Condition and Loop part 2.pdfC Condition and Loop part 2.pdf
C Condition and Loop part 2.pdf
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
Rodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementationRodrigo Almeida - Microkernel development from project to implementation
Rodrigo Almeida - Microkernel development from project to implementation
 
Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005Installation of PC-Lint and its using in Visual Studio 2005
Installation of PC-Lint and its using in Visual Studio 2005
 
GIT training - advanced for software projects
GIT training - advanced for software projectsGIT training - advanced for software projects
GIT training - advanced for software projects
 
LIGGGHTS installation-guide
LIGGGHTS installation-guideLIGGGHTS installation-guide
LIGGGHTS installation-guide
 
Readme
ReadmeReadme
Readme
 
Orangescrum In App Chat Add-on User Manual
Orangescrum In App Chat Add-on User ManualOrangescrum In App Chat Add-on User Manual
Orangescrum In App Chat Add-on User Manual
 
Introduction To programming.pptx
Introduction To programming.pptxIntroduction To programming.pptx
Introduction To programming.pptx
 
DCVCS using GIT
DCVCS using GITDCVCS using GIT
DCVCS using GIT
 
Best practices android_2010
Best practices android_2010Best practices android_2010
Best practices android_2010
 
install k+dcan cable standard tools 2.12 on windows 10 64bit
install k+dcan cable standard tools 2.12 on windows 10 64bitinstall k+dcan cable standard tools 2.12 on windows 10 64bit
install k+dcan cable standard tools 2.12 on windows 10 64bit
 
Esm rel notes_6.0cp1
Esm rel notes_6.0cp1Esm rel notes_6.0cp1
Esm rel notes_6.0cp1
 
Scripting for infosecs
Scripting for infosecsScripting for infosecs
Scripting for infosecs
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
Microcontroller part 8_v1
Microcontroller part 8_v1Microcontroller part 8_v1
Microcontroller part 8_v1
 
Instructions 3-5 pages double space research paper about Eric Sc.docx
Instructions 3-5 pages double space research paper about Eric Sc.docxInstructions 3-5 pages double space research paper about Eric Sc.docx
Instructions 3-5 pages double space research paper about Eric Sc.docx
 

Mehr von Keroles karam khalil

Mehr von Keroles karam khalil (15)

Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
Notes part7
Notes part7Notes part7
Notes part7
 
Homework 5
Homework 5Homework 5
Homework 5
 
Notes part6
Notes part6Notes part6
Notes part6
 
Homework 4 solution
Homework 4 solutionHomework 4 solution
Homework 4 solution
 
Notes part5
Notes part5Notes part5
Notes part5
 
Homework 4
Homework 4Homework 4
Homework 4
 
Homework 3 solution
Homework 3 solutionHomework 3 solution
Homework 3 solution
 
C programming session5
C programming  session5C programming  session5
C programming session5
 
Session 5-exersice
Session 5-exersiceSession 5-exersice
Session 5-exersice
 

Kürzlich hochgeladen

如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
ozave
 
Call Girls in Shri Niwas Puri Delhi 💯Call Us 🔝9953056974🔝
Call Girls in  Shri Niwas Puri  Delhi 💯Call Us 🔝9953056974🔝Call Girls in  Shri Niwas Puri  Delhi 💯Call Us 🔝9953056974🔝
Call Girls in Shri Niwas Puri Delhi 💯Call Us 🔝9953056974🔝
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Business Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay Dubai
Business Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay DubaiBusiness Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay Dubai
Business Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay Dubai
AroojKhan71
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
amitlee9823
 
Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 
Tata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataTata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tata
aritradey27234
 
9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar
GenuineGirls
 
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
shivangimorya083
 
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
nirzagarg
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
amitlee9823
 

Kürzlich hochgeladen (20)

如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
如何办理麦考瑞大学毕业证(MQU毕业证书)成绩单原版一比一
 
Call Girls in Shri Niwas Puri Delhi 💯Call Us 🔝9953056974🔝
Call Girls in  Shri Niwas Puri  Delhi 💯Call Us 🔝9953056974🔝Call Girls in  Shri Niwas Puri  Delhi 💯Call Us 🔝9953056974🔝
Call Girls in Shri Niwas Puri Delhi 💯Call Us 🔝9953056974🔝
 
Business Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay Dubai
Business Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay DubaiBusiness Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay Dubai
Business Bay Escorts $#$ O56521286O $#$ Escort Service In Business Bay Dubai
 
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
(ISHITA) Call Girls Service Jammu Call Now 8617697112 Jammu Escorts 24x7
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
 
Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Kadugodi Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
Tata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tataTata_Nexon_brochure tata nexon brochure tata
Tata_Nexon_brochure tata nexon brochure tata
 
John deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualJohn deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance Manual
 
design a four cylinder internal combustion engine
design a four cylinder internal combustion enginedesign a four cylinder internal combustion engine
design a four cylinder internal combustion engine
 
9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar9990611130 Find & Book Russian Call Girls In Vijay Nagar
9990611130 Find & Book Russian Call Girls In Vijay Nagar
 
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
Call Girls in Malviya Nagar Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts Ser...
 
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
 
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Vikaspuri 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
Why Won't Your Subaru Key Come Out Of The Ignition Find Out Here!
 
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Bangalore Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Hyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRCHyundai World Rally Team in action at 2024 WRC
Hyundai World Rally Team in action at 2024 WRC
 
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
Lucknow 💋 (Genuine) Escort Service Lucknow | Service-oriented sexy call girls...
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
 
What Causes BMW Chassis Stabilization Malfunction Warning To Appear
What Causes BMW Chassis Stabilization Malfunction Warning To AppearWhat Causes BMW Chassis Stabilization Malfunction Warning To Appear
What Causes BMW Chassis Stabilization Malfunction Warning To Appear
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
 

EMBEDDED C