Appunti Embedded Systems
Daniele Paparello
Indice
1 Sistema Embedded 7
1.1 Cosa è un sistema embedded . . . . . . . . . . . . . . . . . . . 7
1.2 Struttura di un sistema embedded . . . . . . . . . . . . . . . . 7
1.3 Categorie Generali di ES . . . . . . . . . . . . . . . . . . . . . 8
1.4 Concetto di REACTIVE . . . . . . . . . . . . . . . . . . . . . 9
1.5 Concetto di REAL-TIME . . . . . . . . . . . . . . . . . . . . 9
1.5.1 Hard Real Time . . . . . . . . . . . . . . . . . . . . . . 9
1.5.2 Soft Real Time . . . . . . . . . . . . . . . . . . . . . . 9
1.5.3 Differenze Real Time e Real Fast . . . . . . . . . . . . 9
1.6 Specifiche tipiche di un ES . . . . . . . . . . . . . . . . . . . . 10
2 Architetture di sistemi embedded 11
2.1 Memory mapped I/O e Interconnect Fabric . . . . . . . . . . . 12
2.2 Variabilità in termini di HW e SW . . . . . . . . . . . . . . . 12
2.2.1 Classificazione processore in termini di ISA . . . . . . . 13
3 Datasheets 14
3.1 Hardware datasheet . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 Reference datasheet . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3 Programmer manual . . . . . . . . . . . . . . . . . . . . . . . 14
4 ISA Design 16
4.1 CISC vs RISC . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.2 Formato e codifica . . . . . . . . . . . . . . . . . . . . . . . . 18
4.3 Operand Addressing Fields: Memory-to-Memory . . . . . . . . 18
4.3.1 4-Address ISA (senza PC) . . . . . . . . . . . . . . . . 18
4.3.2 3-Address ISA . . . . . . . . . . . . . . . . . . . . . . . 19
4.3.3 2-Address ISA . . . . . . . . . . . . . . . . . . . . . . . 19
1
4.3.4 1-Address ISA . . . . . . . . . . . . . . . . . . . . . . . 20
4.4 Operand Addressing Fields: General purpose register . . . . . 21
4.5 Confronto Mem-to-Mem e GPR . . . . . . . . . . . . . . . . . 21
4.6 Istruction Set Architecture Tradeoffs . . . . . . . . . . . . . . 23
4.7 Typical GPR ISA Memory Addressing Modes . . . . . . . . . 23
5 CPU in Embedded Systems 26
5.1 Microchip PIC16F architecture . . . . . . . . . . . . . . . . . 27
5.2 Atmel AVR8 architecture . . . . . . . . . . . . . . . . . . . . . 30
5.3 Microchip PIC32 architecture . . . . . . . . . . . . . . . . . . 31
5.4 STM32 architecture . . . . . . . . . . . . . . . . . . . . . . . . 32
6 The ARM Architectures and ISA 33
6.1 Arm Architecture Family . . . . . . . . . . . . . . . . . . . . . 33
6.2 The Original Instruction Pipeline . . . . . . . . . . . . . . . . 34
6.2.1 Pipeline changes for ARM10 e ARM11 . . . . . . . . . 35
6.3 ARM 7TDMI Core . . . . . . . . . . . . . . . . . . . . . . . . 36
6.4 ARM 9TDMI Core . . . . . . . . . . . . . . . . . . . . . . . . 36
6.5 Interconnection AMBA . . . . . . . . . . . . . . . . . . . . . . 37
6.6 The ARM instruction set . . . . . . . . . . . . . . . . . . . . . 38
6.6.1 Thumb Instruction set . . . . . . . . . . . . . . . . . . 38
6.6.2 The Registers . . . . . . . . . . . . . . . . . . . . . . . 40
6.6.3 The Program Status Registers (CPSR e SPSR) . . . . 41
6.6.4 The Program Counter (R15) e il Link Register (R14) . 42
6.6.5 ARM Instruction Set Format . . . . . . . . . . . . . . 42
6.6.6 The Condition Field . . . . . . . . . . . . . . . . . . . 43
6.7 Branch Instrucitons . . . . . . . . . . . . . . . . . . . . . . . . 44
6.8 Data processing Instructions . . . . . . . . . . . . . . . . . . . 45
6.8.1 Data processing Instructions Format . . . . . . . . . . 47
6.9 The Barrel Shifter . . . . . . . . . . . . . . . . . . . . . . . . . 49
6.9.1 Logical Left Shift . . . . . . . . . . . . . . . . . . . . . 49
6.9.2 Logical Right Shift . . . . . . . . . . . . . . . . . . . . 49
6.9.3 Arithmetic Shift Right . . . . . . . . . . . . . . . . . . 49
6.9.4 Rotare Right . . . . . . . . . . . . . . . . . . . . . . . 50
6.10 Load/Store Instructions . . . . . . . . . . . . . . . . . . . . . 50
6.10.1 Load/Store Instructions Format . . . . . . . . . . . . . 51
6.10.2 Single register data transfer . . . . . . . . . . . . . . . 52
6.11 Effect of endianess . . . . . . . . . . . . . . . . . . . . . . . . 56
2
6.12 Block Data Transfer . . . . . . . . . . . . . . . . . . . . . . . 57
6.13 Stack Operation and Direct functionality of Block Data Transfer 58
6.13.1 Stacks and Subroutines . . . . . . . . . . . . . . . . . . 60
6.13.2 Block Copy . . . . . . . . . . . . . . . . . . . . . . . . 61
6.14 Swap and Swap Byte Instructions . . . . . . . . . . . . . . . . 62
6.15 Software Interrupt(SWI) . . . . . . . . . . . . . . . . . . . . . 62
7 Memory and memory map 64
7.1 Confronto SRAM e DRAM . . . . . . . . . . . . . . . . . . . . 65
7.2 Flash memory . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7.3 Bus Memory bandwidth . . . . . . . . . . . . . . . . . . . . . 66
7.4 Buffer or accelerator unit . . . . . . . . . . . . . . . . . . . . . 67
7.5 Example: Flash accelerator in STM32 . . . . . . . . . . . . . . 68
7.6 Bus matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
7.7 Memory in 8-bit and 32-bit architectures . . . . . . . . . . . . 71
7.8 Memory mapped I/O . . . . . . . . . . . . . . . . . . . . . . . 72
7.9 Memory map: 8-bit microcontroller PIC16-F648 . . . . . . . . 73
7.9.1 Program Memory . . . . . . . . . . . . . . . . . . . . . 74
7.9.2 Data Memory . . . . . . . . . . . . . . . . . . . . . . . 74
7.10 Memory map: 8-bit microcontroller ATmega128(ATMEL) . . 77
7.10.1 Program Memory . . . . . . . . . . . . . . . . . . . . . 78
7.10.2 Data Memory . . . . . . . . . . . . . . . . . . . . . . . 78
7.11 Memory map: 32-bit microcontroller
STM32F401 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
7.11.1 Blocchi 0-1 . . . . . . . . . . . . . . . . . . . . . . . . 80
7.11.2 Blocco 2 . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7.11.3 Bit banding region (ARM Cortex specific) . . . . . . . 83
8 GPIO Devices 86
8.1 GPIO basic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
8.2 GPIO general circuit example . . . . . . . . . . . . . . . . . . 87
8.3 GPIO example PIC16-F628 . . . . . . . . . . . . . . . . . . . 91
8.4 GPIO example ATmega . . . . . . . . . . . . . . . . . . . . . 95
8.4.1 Metastability and 2-FF synchronizer . . . . . . . . . . 97
8.4.2 Weak pull-up . . . . . . . . . . . . . . . . . . . . . . . 98
2 ATmega . . . . . . . . . . . . . . . . . . . . 99
8.5 GPIO example
8.6 GPIO example Atmega registers . . . . . . . . . . . . . . . . . 101
8.7 GPIO example ST32F . . . . . . . . . . . . . . . . . . . . . . 102
3
8.7.1 GPIO example ST32F- Registers . . . . . . . . . . . . 104
8.7.2 Input-floating/pull up/pull down configurations . . . . 105
8.7.3 Output Configuration . . . . . . . . . . . . . . . . . . . 105
8.7.4 High Impedance-analog Configuration . . . . . . . . . . 106
9 Timers 107
9.1 Input Capture Functions . . . . . . . . . . . . . . . . . . . . . 107
9.2 Output Compare Functions . . . . . . . . . . . . . . . . . . . 109
9.3 PWM Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 110
9.4 H-bridge and dead time . . . . . . . . . . . . . . . . . . . . . 111
9.4.1 PWM generation with Dead Time . . . . . . . . . . . . 112
9.5 RTC Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 114
9.6 ATmega Timers: 8bit Timer/Counter . . . . . . . . . . . . . . 114
9.6.1 Clear Timer on Compare Match (CTC) . . . . . . . . . 116
9.6.2 Fast PWM Mode . . . . . . . . . . . . . . . . . . . . . 117
9.6.3 Prescaler for Timer . . . . . . . . . . . . . . . . . . . . 118
9.7 ATmega Timers: 16bit Timer/Counter . . . . . . . . . . . . . 120
9.7.1 Input Capture function . . . . . . . . . . . . . . . . . . 121
9.7.2 Output Compare function . . . . . . . . . . . . . . . . 122
9.8 Microchip PIC-Power control PWM . . . . . . . . . . . . . . . 124
9.9 STM32-advanced control timer . . . . . . . . . . . . . . . . . 125
10 Clock generation in MCU 127
10.1 Clock tree-ATmega . . . . . . . . . . . . . . . . . . . . . . . . 128
10.2 Clock tree-STM32 . . . . . . . . . . . . . . . . . . . . . . . . . 129
10.3 Watchdog Timer . . . . . . . . . . . . . . . . . . . . . . . . . 131
11 Interrupts, Interrupt controller, Vector table 133
11.1 Interrupt Latency . . . . . . . . . . . . . . . . . . . . . . . . . 134
11.2 ARM Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . 135
11.3 Review of ARM Interrupts . . . . . . . . . . . . . . . . . . . . 136
11.4 Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
11.5 Enabling IRQ and FIQ . . . . . . . . . . . . . . . . . . . . . . 137
11.6 ARM Vector Table . . . . . . . . . . . . . . . . . . . . . . . . 138
11.7 Types of Interrupt . . . . . . . . . . . . . . . . . . . . . . . . 141
11.8 Jumping to the Interurpt Handler . . . . . . . . . . . . . . . . 142
11.8.1 Auto-vectored Interrupts . . . . . . . . . . . . . . . . . 142
11.8.2 Vectored Interrupts . . . . . . . . . . . . . . . . . . . . 143
4
11.9 Timing of Interrupts . . . . . . . . . . . . . . . . . . . . . . . 143
11.10The ARM AIC (Advanced Interrupt Controller) . . . . . . . . 144
11.10.1 AIC Automatic Vectoring Benefit . . . . . . . . . . . . 150
11.10.2 AIC IRQ Priority Management . . . . . . . . . . . . . 150
11.11Interrupt Controller in Cortex ARMv7 architecture . . . . . . 153
11.11.1 ARMv7 Cortex status register . . . . . . . . . . . . . . 153
11.12Interrupt in ATmega MCU . . . . . . . . . . . . . . . . . . . . 155
11.12.1 Program memory map and bootloader support . . . . . 156
12 Communication devices for Embedded Systems 158
12.1 Open System Interconnection Layering . . . . . . . . . . . . . 159
12.2 Point-to-point netowrks & Shared media netowrks . . . . . . . 160
12.3 Network resources & qualitative parameters . . . . . . . . . . 161
12.3.1 Event baset communication & state based communi-
cation . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
12.4 Aynchronous serial communciations . . . . . . . . . . . . . . . 162
12.4.1 Physical layer . . . . . . . . . . . . . . . . . . . . . . . 163
12.4.2 Data link layer . . . . . . . . . . . . . . . . . . . . . . 164
12.5 Clock recovery in UART devices . . . . . . . . . . . . . . . . . 166
12.6 Timing Accuracy . . . . . . . . . . . . . . . . . . . . . . . . . 169
12.7 USART device on AVR . . . . . . . . . . . . . . . . . . . . . . 171
12.8 SPI Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
12.8.1 SPI Multiple slave architecture . . . . . . . . . . . . . 177
12.9 SPI device on Atmel ATmega . . . . . . . . . . . . . . . . . . 179
12.10SPI: advantages and Disadvantages . . . . . . . . . . . . . . . 181
2
12.11I C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
12.11.1 SDA and SCL signals . . . . . . . . . . . . . . . . . . . 183
2
12.11.2 I C data transmission . . . . . . . . . . . . . . . . . . 185
2
12.11.3 I C Arbitration . . . . . . . . . . . . . . . . . . . . . . 187
2
12.11.4 I C Addressing and Transfering . . . . . . . . . . . . . 189
2
12.11.5 I C 10-bit addressing . . . . . . . . . . . . . . . . . . . 192
2
12.11.6 I C Electrical Characteristics . . . . . . . . . . . . . . 193
12.12CAN bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
12.12.1 CAN-bus Physical layer . . . . . . . . . . . . . . . . . 198
12.12.2 CAN-bus Bit timing . . . . . . . . . . . . . . . . . . . 200
12.12.3 CAN-bus Bit stuffing . . . . . . . . . . . . . . . . . . . 201
12.12.4 CAN-bus Frames . . . . . . . . . . . . . . . . . . . . . 202
5
13 Embedded System Toolchain 204
13.1 The GNU toolchain . . . . . . . . . . . . . . . . . . . . . . . . 207
13.1.1 GNU make . . . . . . . . . . . . . . . . . . . . . . . . 208
13.1.2 GNU Compiler Collection (GCC) . . . . . . . . . . . . 208
13.2 Gcc compile, assemble and link . . . . . . . . . . . . . . . . . 209
13.2.1 Gcc-compile . . . . . . . . . . . . . . . . . . . . . . . . 209
13.2.2 Gcc assemble . . . . . . . . . . . . . . . . . . . . . . . 213
13.2.3 Gcc link . . . . . . . . . . . . . . . . . . . . . . . . . . 214
13.2.4 GNU Binutils . . . . . . . . . . . . . . . . . . . . . . . 215
13.3 GNU C Library . . . . . . . . . . . . . . . . . . . . . . . . . . 215
13.4 ABI (application binary interface) . . . . . . . . . . . . . . . . 215
13.5 ELF Binary output format . . . . . . . . . . . . . . . . . . . . 217
14 Embedded Systems software structure, code and data 221
14.1 Assembly program source file (ARM) . . . . . . . . . . . . . . 221
14.2 Linker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
14.2.1 Symbol Resolution . . . . . . . . . . . . . . . . . . . . 223
14.2.2 Relocation . . . . . . . . . . . . . . . . . . . . . . . . . 226
14.3 Linker -ld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
14.4 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . 236
14.5 C Startup: linker & linker script . . . . . . . . . . . . . . . . . 237
14.5.1 Stack placement . . . . . . . . . . . . . . . . . . . . . . 238
14.5.2 Gloabl Variables . . . . . . . . . . . . . . . . . . . . . 240
14.5.3 C code compilation . . . . . . . . . . . . . . . . . . . . 243
6
Capitolo 1
Sistema Embedded
1.1 Cosa è un sistema embedded
Un sistema embedded (ES ) è un sistema elettronico nascosto che fa parte di
un sistema più complesso o di un prodotto utile all’uomo. La parte elettronica
è fondamentale per il funzionamento del prodotto stesso, ma il prodotto non
viene comprato per la sua elettronica bensı̀ per la funzionalità fisica che offre
all’utente. L’ES si deve adattare alle condizioni in cui dovrà operare: le
specifiche saranno diverse a seconda dell’applicazione. In conclusione, un ES
è un qualunque sistema in cui l’utente non vuole sapere che esso includa un
processore.
1.2 Struttura di un sistema embedded
User : interagisce con il processo fisico grazie alla parte computazionale; Sen-
sor : acquisisce informazioni dal processo fisico; Actuator : controlla il proces-
so fisico. Attuatori e Sensori sono solitamente analogici e elettromeccanici.
Vediamo le caratteristiche che deve avere un ES :
• REACTIVE : l’ES deve reagire ad una velocità sufficiente a controllare
correttamente il processo: deve acquisire i dati, elaborare e control-
7
lare. Di conseguenza, è sufficiente che il feedback abbia una velocità
adeguata. Mentre nei general porpouse la velocità (f ) è sinonimo di
ck
prestazioni, negli ES basta solo avere una f adeguata al controllo
ck
corretto del processo. Tutta la potenza di calcolo aggiuntiva (oltre le
specifiche) si paga in termini di costi aggiuntivi del prodotto e consumo
aggiuntivo del prodotto.
• ETEROGENEOUS : è composto da diverse parti non tutte di tipo elet-
tronico. A tale proposito esistono numerosissime architetture proprio
perché ogni architettura è migliore per una data applicazione
• NETWORKED (connesso) : un ES può essere condiviso fra più pro-
cessi fisici. I segnali provenienti da un sistema possono essere usati
per controllarne un altro. Si parla di ES distribuiti quando si ha una
distribuzione di processi fisici e di parti elettroniche che lavorano in-
sieme. Nella rete non è importante solo la velocità, ma anche altre
caratteristiche quali robustezza, sicurezza, tolleranza al fallimento.
1.3 Categorie Generali di ES
Esistono quattro categorie generali di ES :
• GENERAL COMPUTING : richiedono prestazioni e caratteristiche si-
mili a un general porpouse, ma in package o condizioni diversi. Di
conseguenza cambiano le specifiche su costo, dimensioni e consumo;
• CONTROL SYSTEM : interagiscono con il sistema fisico attraverso un
feedback;
• SIGNAL PROCESSING: sistemi dedicati all’elaborazione numerica di
segnali (DSP). Troviamo calcoli pesanti da eseguire su grandi moli di
dati;
• COMMUNICATION E NETWORKING: servono a spostare i dati fra
interfacce e collegare fra loro vari sistemi. La mole computazionale è
nettamente inferiore ai DSP in quanto i dati non vengono elaborati ma
solo “spostati”. 8
1.4 Concetto di REACTIVE
Un ES incontra eventi di due tipi:
• PERIODICI: ripresentati preiodicamente o più volte dal processo
• APERIODICI o ASINCRONI: provengono dall’utente o sono allarmi
occasionali
1.5 Concetto di REAL-TIME
Cosı̀ come “veloce” è la specifica principale dei general porpouse, il real time è
la specifica più comune e più importante per i sistemi embedded. Real time
significa che la velocità deve essere sufficiente a controllare correttamente il
processo.
1.5.1 Hard Real Time
Si tratta di una specifica stringente: esiste un tempo t (a volte anche
M AX
t ) al di fuori del quale il calcolo eseguito diventa inutile. Una violazione
M IN
di tale specifica è di tipo catastrofico (e.g:drone che riconosce tardi un
ostacolo);
1.5.2 Soft Real Time
Si tratta di una specifica poco stringente: esiste un tempo t al di fuori
M AX
del quale il calcolo eseguito tende a perdere di utilità. Una violazione di tale
specifica non è catastrofica (e.g: perdita di un frame in un lettore video)
1.5.3 Differenze Real Time e Real Fast
• REAL FAST: voglio che l’elaborazione sia più veloce possibile : tutti
i processi hanno la stessa priorità e un tempo di esecuzione breve ma
incognito;
• REAL TIME: voglio che in ogni caso l’elaborazione sia completa prima
dello scadere della t (deadline). Ogni processo vede associata una
M AX
sua priorità e il tempo di esecuzione è noto e sotto controllo.
9
1.6 Specifiche tipiche di un ES
• SIZE-WEIGHT : il sistema elettronico deve essere inserito in un qual-
cosa e quindi deve adeguarsi in termini di grandezza e peso;
• LOW POWER: non essendo l’elettronica la parte ponderante, le bat-
terie e i sistemi di raffreddamento sono limitati;
• HARSH ENVIROINMENT : ambiente inospitale. L’ES deve resiste-
re a shock, vibrazioni, calore, interferenza, cali di tensione, acqua,
corrosione, o tutto quello che si può incontrare in un sistema esterno;
• SAFETY CRITICAL OPERATION : l’ES deve contemporaneamente
funzionare correttamente e non funzionare in modo sbagliato;
• EXTREME COST SENSITIVITY : il costo dell’elettronica deve esse-
re contenuto rispetto al prezzo complessivo del
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
Scarica il documento per vederlo tutto.
-
Riassunti Biomateriali
-
Sistemi Distribuiti - Riassunti
-
Riassunti Biomatematical modeling
-
Fisica I - riassunti