Introduction to Firmware
-
Upload
caroline-murphy -
Category
Devices & Hardware
-
view
1.514 -
download
2
Transcript of Introduction to Firmware
![Page 1: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/1.jpg)
FIRMWARE
2016
![Page 2: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/2.jpg)
01Background
![Page 3: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/3.jpg)
3 // Background
An Embedded System is:
● A computer processor with a dedicated purpose● Part of a larger electronic device (“embedded”)● Not intended to be a general-purpose computer
Any device that contains a processor, but isn’t a PC or smartphone!
![Page 4: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/4.jpg)
4 // Background
Firmware is Embedded Software
● Runs on embedded systems● Directly controls electronic (or mechanical) hardware● Historically, this software was set in stone at manufacturing time,
essentially becoming part of the hardware → “firmware”○ Today, many devices have updatable firmware
![Page 5: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/5.jpg)
02What’s different?
![Page 6: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/6.jpg)
6 // What’s different?
● Runs on a general-purpose device
● User-centric, graphical
● Operating system mediates hardware access
● State of the art hardware
● A variety of higher-level programming languages
● An integral part of the device
● Primitive or no user interface
● Direct hardware access
● Primitive hardware capabilities
● Programmed in low-level languages such as C or assembly
![Page 7: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/7.jpg)
What’s different?
System constraints define firmware programming
![Page 8: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/8.jpg)
● RAM● Program Storage● Speed● Math● Libraries● Operating System● Debugging Capabilities
8 // What’s different?
Constraints
![Page 9: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/9.jpg)
03What Lies Beneath
![Page 10: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/10.jpg)
● Digital○ General Purpose Input/Output (GPIO)○ Serial communications (SPI, I2C, etc)○ USB
● Analog○ Analog-to-digital converters (ADC)
● Specialized Peripherals○ Radio on-chip (Bluetooth, ZigBee, Thread, RF4CE, etc)
10 // Hardware
Interfacing to the outside world
![Page 11: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/11.jpg)
11 // Hardware
Memory Mapped I/O
Address Decoder
Memory Cell
EnableRead/Write
Address Bus
Data Bus
Normal Memory
Latch & Amplifier
Address Decoder
EnableRead/Write
Address Bus
Data Bus
LED
GPIO
Address Decoder
Peripheral
EnableRead/Write
Address Bus
Data Bus
Generic Peripheral
![Page 12: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/12.jpg)
12 // Hardware
Harvard Architecture Von Neumann Architecture
![Page 13: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/13.jpg)
● The most primitive form of multitasking● The interrupt vector stores callback functions● Hardware triggers the CPU to invoke these functions in response to
certain events○ Timer elapsing○ Data arriving on serial interface○ Many more!
13 // Hardware
Interrupts
![Page 14: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/14.jpg)
04Tools and Techniques
![Page 15: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/15.jpg)
● Usually C, sometimes assembly○ Must allow addressing specific memory locations
● Low-level programming style -- abstraction is expensive○ global variables○ fixed-size arrays○ avoid passing large objects on the stack
● Very often you’re counting every byte○ fixed-width types are preferred○ bitwise operations are common
15 // Tools and Techniques
Programming Language
![Page 16: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/16.jpg)
● ISRs must be fast!● Only has access to global state● Great care must be taken when main thread accesses shared global
state○ Turn off interrupts (“go atomic”)○ Use CPU instructions that are guaranteed to be atomic
● You can poll the interrupt flags when interrupts are turned off
16 // Hardware
Interrupt Service Routines
![Page 17: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/17.jpg)
17 // Hardware
Concurrency Fun
35 FF FF FF
clock
FF
currentTime
35 FF FF FF FF FF
36 00 00 00
Interrupt fires!
00 FF FF
36 00 00 00 36 00 FF FF
currentTime = clock;
![Page 18: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/18.jpg)
18 // Tools and Techniques
Compiler/IDE
● Expensive, awkward, buggy● Cross-compiled from your computer● Emulators are not usually useful because of the tight coupling to
external hardware
![Page 19: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/19.jpg)
● No obvious sign! It’s just a brick● Logging is not always available● Stack traces are not always available● External hardware is required to debug● Limited number of breakpoints!● LEDs are pretty great
19 // Tools and Techniques
When things go wrong...
![Page 20: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/20.jpg)
20 // Tools and Techniques
Programming/Debug Hardware
● Expensive, awkward, buggy● Some device interfaces are proprietary, but there are also standards
such as JTAG or SerialWire
![Page 21: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/21.jpg)
21 // Tools and Techniques
Test Equipment
● Multimeters● Oscilloscopes● Logic Analyzers
![Page 22: Introduction to Firmware](https://reader033.fdocuments.in/reader033/viewer/2022052117/5879bc261a28ab6b2c8b82bb/html5/thumbnails/22.jpg)
Key Takeaway
Embedded systems are “small”