Phillip Stanley-Marbell
Foundations of
Embedded Systems
Physical Constraints, Sensor Uncertainty, Error Propagation,
Low-Level C on RISC-V, and Open-Source FPGA Tools
Draft Version of Michaelmas 2020
1
Introduction
Figure 1.1: Embedded
systems bridge the gap
between analog signals
in the physical world and
digital systems / software.
All software eventually works;
all hardware eventually fails.
Clod Berrera.
Table 1.1: Concepts.
Concept Section
Microcontroller § 1.1.5
Microprocessor § 1.1.5
DSP § 1.1.5
Architecture § 1.3.2
Host § 1.3.2
Target § 1.3.2
Cross-Compiler § 1.3.2
JTAG § 1.3.2
SWD § 1.3.2
Transduction § 1.3.4
ADCs/DACs § 1.3.4
FPGA § 1.6
How do you design the circuits and software for a new embedded system,
starting from only the specification of what integrated circuits to use? How
do you design a new general-purpose embedded system such as the BBC mi-
cro:bit or a new special-purpose embedded system from the ground up, start-
ing only from the specification of the intended function? Does knowing how
to program an Arduino or Raspberry Pi provide you all the insight you need
as an engineer, to design such systems from the ground up? How do you
interface (electrically and otherwise) with sensors that have digital interfaces
such as I2C and SPI and how can you quantify the inevitable noise associated
with sensor measurements? How can you estimate the power dissipation of
an embedded system you have designed, as a function of parameters such
as software-configured microcontroller clock frequency, supply voltage, and
temperature? Where would you look for the information you would need to
perform such an analysis? How do you go about writing the firmware or a
custom operating system for a completely new hardware design for which
no firmware exists? In this chapter, we will outline the technical content of
2 phillip stanley-marbell
the rest of the course and begin to answer questions such as these.
1.1 Intended Learning Outcomes
At the end of this chapter, you should be able to: enumerate the important
components in an embedded system design; read and interpret the datasheet
for a component in a system or for an entire system; propose and design
changes to a system to extend its uses.
1.1.1 Learning outcomes pre-assessment
Complete the following
quiz to evaluate your prior knowledge of the material
for this chapter.
1.1.2 Things to think about
Complete the following
thinking exercise to stimulate your thoughts about
the contents of this chapter before proceeding with the material.
1.1.3 Things to look out for
Concepts people sometimes get confused by in this chapter include:
1. What factors affect power dissipation.
2. How much C and assembly language programming you will have to do
in this course.
3. How the coursework will be assessed.
4. Whether you are expected to know the answers to all the items in the quiz
below, or whether they are topics which will be covered in this course.
1.1.4 The muddiest point
As you go through the material in this chapter, think about the following two
questions and note your responses for yourself or using the annotation tools
of the online version of the chapter. You will have the opportunity to submit
your responses to these questions at the end of the chapter:
1. What is least clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
2. What is most clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
foundations of embedded systems 3
1.1.5 Quiz
In the next three minutes, quickly mark those of the 50 questions below which
you think you can explain to someone in less than 15 seconds. At the end
of the three minutes, pick one of the questions that does not have a sim-
ple “yes”/“no” answer. Tell the other members of your breakout discussion
group which question you chose and wait for them to read that question.
Next, try to explain your answer to them in under 30 seconds.
1. Is an embedded system that needs to have its battery replaced every week,
or which needs to be recharged every day, still useful?
2. What property of an embedded system dictates its battery life?
3. How do you quantify the energy efficiency of a computing system?
4. How would you define power dissipation for an embedded system?
5. On what parameters does the power dissipation of an embedded system
depend? What is an approximate analytic relationship between the power
dissipation of an embedded system and each of these parameters?
6. Does power dissipation matter for systems that are connected to the elec-
trical grid?
7. Does power dissipation matter for systems that are powered off solar
power?
8. Does power dissipation matter for systems that are powered by forms of
scavenged energy other than solar power?
9. In what ways can a system which uses less power on average use more
energy overall for a given task?
10. Does lower power dissipation necessarily mean longer battery life?
11. What is the typical average scavenged power that you can obtain from a
photovoltaic cell per square centimeter of the cell’s area in broad daylight?
What about in an office building?
12. What is the typical average power you can obtain from a state-of-the-art
MEMS-based vibrational energy scavenger?
13. What are some of the types (chemistries) for batteries?
14. What are supercapacitors?
15. How do supercapacitors differ from batteries?
16. What is VHDL (covered in 1P3)?
4 phillip stanley-marbell
17. What is Verilog?
18. What are some different number representations such as fixed point, 2’s
complement (covered in 1P3)?
19. What is an ADC? What is a DAC (covered in 1P3)?
20. What is a microprocessor and what are it’s primary components (covered
in 1P3)?
21. What are some of the typical electrical interfaces between sensors and
embedded processors or microcontrollers?
22. What is SPI?
23. What is I2C?
24. What is MIPI DSI? What about MIPI CSI?
25. Which of I2C/SPI/MIPI CSI/DSI interfaces would you typically find on
a microcontroller or embedded processor?
26. What is a microprocessor pipeline?
27. What are the typical stages of a microprocessor’s pipeline?
28. What is a computer’s architecture (covered in 1P3)?
29. What is the difference between architecture and microarchitecture (cov-
ered in 1P3)?
30. What is an algorithm (covered in 1P4)?
31. What does the C programming language keyword volatile indicate?
(covered in Part IIA Project, GF2 (C/C++)?)
32. What is the relationship between clock frequency and dynamic power
dissipation for CMOS (covered in 2P8?)?
33. What is the relationship between supply voltage and maximum clock
frequency for CMOS (covered in 2P8?)?
34. What is the relationship between temperature and leakage power dissi-
pation for CMOS (covered in 2P8?)?
35. Can you sketch the CMOS circuit for an inverter? How does it work?
36. What logic gates would you need to construct an adder?
foundations of embedded systems 5
37. If you have an analog signal (say, human voice) that you need to digitize,
how would you go about determining the frequency at which to sample
it? For human voice, what would be that sampling frequency?
38. Besides sampling rate, what other aspects would you need to consider in
sampling a signal?
39. Do you know the principles of operation of all common sensors used in
embedded systems?
40. Can you numerically quantify measurement uncertainty and noise in
outputs given a system design?
41. Can you propagate measurement uncertainties, quantified as standard
deviations, through a sequence of arithmetic operations on measurements
with those associated uncertainties?
42. Can you derive the method for propagating uncertainties represented as
standard deviations from first principles?
43. What is the fundamental property of a transistor technology that makes it
possible for everything from microcontrollers and sensors, to microproces-
sors, to still manage to operate in the inevitable presence of manufacturing
process variations and electrical noise?
44. What is a linker script file?
45. Are you familiar with ARM assembly language?
46. Are you familiar with the Cortex-M0 instruction subset of the ARM in-
struction set architecture?
47. Would you have no trouble writing a program in which one of the rou-
tines is in assembler and the rest in C?
48. Are you familiar with the STABS debugging format?
49. Do you know what ANCI C trigraphs are?
50. What is the role of crt0.s in the linker?
1.2 Motivation: Sensing, Computation, I/O, and Displays
Anyone can program embedded systems. You cannot really understand em-
bedded systems, let alone design new embedded systems from the ground
up, or even begin to address research challenges in embedded systems, if
you cannot program in C and assembler. In the same way, you can’t be a
surgeon if you don’t have a basic understanding of biology. And, once you
6 phillip stanley-marbell
can program the processor in an embedded system, you need to understand
how to interface such a processor to sensors (e.g., inertial or temperature sen-
sors) and actuators (e.g., displays or motors), because embedded systems by
definition are computing systems that interact with the physical world and
they achieve this interaction through sensors and actuators.
1.3 The FRDM-KL03 and FRDM-KL05 Development Platforms
In this course, we will use the FRDM-KL03 and FRDM-KL05 development
platforms from Freescale
1,2
(Figure
1.3 and Figure 1.2). The FRDM-KL03 and
1
Freescale Semiconductor
2014c.
2
Freescale Semiconductor
2014a.
FRDM-KL05 are built around an ARM Cortex-M0+ microcontroller. They are
similar in many ways to the NUCLEO-F746ZG board and the STM32 Nucleo-
64 boards with which some students at Cambridge may be familiar.
Unlike the NUCLEO-F746ZG, the FRDM-KL03 and FRDM-KL05 both have
a sensor integrated (a 3-axis accelerometer). They also contain a tri-color LED
and are power-efficient enough to be powered from a coin cell batter y. For
these reasons, the FRDM-KL03 and FRDM-KL05 are useful for an introduc-
tory course on embedded systems.
In this course, you will lear n how to get programs running directly over
the microcontroller, without using an embedded operating system such as
Mbed and without having to resort to graphical tools such as those provided
with Arduino. As a result, you will have the opportunity to understand how
embedded systems work from the ground up.
Figure 1.2: The Freescale
FRDM KL03 platform we
will use in this course.
Images sources: Freescale
Semiconductor.
In this course, you will learn the fundamentals of C programming for
embedded systems and the specifics of how such C programs interact with
a microcontroller’s architecture. You will also learn the details of how to
compile C programs to run directly over a processor in the absence of an
foundations of embedded systems 7
Figure 1.3: The Freescale
FRDM KL05 platform we
will use in this course.
Images sources: Freescale
Semiconductor.
operating system (Chapter
4).
You will learn about the communication interfaces such as I2C, SPI, and I
2
S
used in embedded systems (Topic
9), you will interface a microcontroller with
displays using these interfaces (Topic
12 and Coursework item #2) and you
will interface a microcontroller with power measurement circuits (Course-
work item #3), again using communication interfaces such as I2C and SPI.
The FRDM-KL03 and FRDM-KL05 development platforms have an inte-
grated 3-axis accelerometer (Freescale MMA8451Q
3
). You will learn how to
3
Freescale Semiconductor
2014d.
interface with sensors such as the MMA8451Q and how to quantify the un-
certainty in measurements from sensors (Topic
2).
1.3.1 The Cortex-M0+ processor in the FRDM-KL03 and FRDM-KL05
The Cortex-M0+ processor in the FRDM-KL05 development platform is a
Freescale MKL05Z32VFM4
4
KL05 with 32 KB nonvolatile memory (Flash)
4
Freescale Semiconductor
2014c.
and 4 KB volatile memory (SRAM). The Cortex-M0+ processor in the FRDM-
KL03 development platform is a Freescale MKL03Z32VFK4
5
with 32 KB Flash
5
Freescale Semiconductor
2014b.
and 2 KB SRAM, half the SRAM in the KL05. The description below for the
KL05 applies identically to the KL03, except for the difference in SRAM.
Most of the pins of the processor are made available on the headers along
the sides of the FRDM platforms (see Figure
1.3(a)), making it possible to
use the FRDM platforms to prototype new system designs. In this course,
we have soldered pins onto these headers making it possible for you to plug
the board into one of the supplied breadboards and to wire together multiple
boards using the jumper wires also supplied in the course kit.
1.3.2 Loading code to the KL03/KL05: The auxiliary OpenSDA processor
To load programs into the memor y of the microcontroller in order to run
them, most microcontrollers use the JTAG
6
interface or one of it’s variants,
6
IEEE Std. 1149.1-1990.
8 phillip stanley-marbell
such as SWD.
7
JTAG and SWD are both electrical interfaces and logical pro-
7
Serial Wire Debug (SWD).
tocols, and all embedded processors will have one or more pins fully- or
partially-dedicated to these interfaces. We will cover the JTAG and SWD in-
terfaces in detail in Topic
9. In typical use, you will develop your code on
your personal computer (henceforth, the host) and will compile it using a
compiler that runs on the host machine (e.g., Linux running on an Intel pro-
cessor) but which generates binaries for the target ARM architecture. Such a
compiler is typically referred to as a cross-compiler, and we will cover compil-
ing programs for embedded systems in Topic
4 and Appendix 1.
Because most PCs do not have the JTAG interfaces that you would need
on your host machine to program the target device, embedded systems are
usually programmed using a debug interface. Debug interfaces are custom
electronics that you plug into your PC’s USB port and which can connect
to the microcontroller’s JTAG pins. There are several companies that make
such hardware and popular vendors include SEGGER (who make the JLink
system) and PE-Micro. In the FRDM-KL03 and FRDM-KL05 development
platforms, one of these debug interfaces is integrated directly onto part of
the board, so you just need to plug the board into your host PC without need
for a special debug cable. It so happens that this debug interface is also imple-
mented using a microcontroller (a Freescale K20DX128VFM5), so the FRDM-
KL03 and FRDM-KL05 development platforms actually have two processors
on board: a K20DX128VFM5 and a KL05Z32VFM4 or KL03Z32VFK4. You
will only be running your programs on the KL05Z32VFM4 or the KL03Z32VFK4
which we will henceforth refer to simply as “the board’s processor or “the
board’s microcontroller”.
1.3.3 Programming the KL03/KL05: Bare metal and the memory map
When writing software in a low-level language such as C on your host PC,
even though you can in principle directly address memory at any given ad-
dress, you typically do not. On a PC you ordinarily should never directly
reference arbitrary memory addresses, because of the restrictions placed by
the hardware and operating system’s cooperation to protect access to mem-
ory.
In embedded systems that are small and cheap enough to embed within
everyday objects, the processors employed are memory-constrained and typ-
ically do not run an operating system. Programs running on such systems
therefore typically run “over bare metal”. It is on such systems that we will
focus in this course. The KL03 is one of the smallest ARM Cortex-M0+
implementations and is available in integrated circuit packages as small as
2 mm×1.6 mm (Figure
1.4). The FRDM-KL03 and FRDM-KL05 development
platforms therefore provide an exemplary platform of the state of the art for
foundations of embedded systems 9
deeply-embedded systems.
Figure 1.4: The Freescale
KL03 Cortex-M0+ mi-
crocontroller comes in
IC packages as small as
2 mm×1.6 mm (smaller
than the dimples on a
golf ball). Image source:
Freescale Semiconductor.
Programs running on microcontrollers typically interface with peripherals
(components other than computation, such as timers, communication inter-
faces, or interfaces to pins) through memory-mapped I/O. Memory-mapped
I/O, paired with interrupts, is the way in which most software initiates inter-
action with hardware peripherals. The process involves writing and reading
one or more bytes to a specific memory address where the bytes written will
be interpreted as a specific command or bytes read will be interpreted as
a response. Memory-mapped interface addresses to hardware peripherals
are conceptually treated as registers, and are usually referred to as memory-
mapped registers. We will discuss memory mapped I/O in C programs in
Topic
4. For these reasons, it is essential to know what a given embedded
processor’s memory map looks like. Figure 1.5 shows the memory map of the
KL05Z32VFM4 processor used in the FRDM-KL05 development platform.
Figure 1.5: Part of the
memory map of the KL05
family of microcontrollers.
Table source: Freescale
Semiconductor, KL05 Sub-
Family Reference Manual,
Rev. 3.1, November 2012.
The memory map in Figure
1.5 represents the entire memory space ad-
dressable by the processor. This includes volatile memory (SRAM, from
0x1FFF FC00 to 0x2000 0BFF), non-volatile memory (Flash, from 0x0000 0000
to 0x07FF FFFF) and memory mapped I/O. Flash is typically used to store
program code, although an executing program can also store data values to
10 phillip stanley-marbell
Flash. You should think of the values which you write to memory-mapped
registers as commands: The values are not stored at that address, but rather
are taken by the hardware peripheral to which that register corresponds, to
indicate a command.
The region of memory that comprises a program, stored in Flash, has a
specific layout comprising the executable program code, data for program
constants, and so on. The layout of this region is determined by the linker,
which we will discuss further in Topic
4.
You can, in principle, write a single C program, together with some as-
sembly language code for processor initialization
8
that implements all the
8
For most target architec-
tures, you will at the very
least need a few lines of
assembly code to initial-
ize the processor’s stack
pointer.
software for your embedded system without the need for any libraries or for
an operating system. We will see one such example in Topic
4. In practice
however, it is often useful to use a software development kit (SDK). An SDK may
contain a full operating system, but typically also contains several helper rou-
tines that you can use to ease interaction with a microcontroller’s peripherals
even if you do not require an operating system. For example, the are specific
sequences of reads and writes from memory-mapped registers that you must
perform to toggle a microcontroller’s general-purpose I/O (GPIO) pins, or to
read data from one of its communication interfaces from a sensor. We will
use the Kinetis SDK (KSDK) from Freescale to provide useful helper routines.
1.3.4 Using the FRDM-KL03 and FRDM-KL05: Sensors
Sensors are fundamental to embedded systems: There is no reason to em-
bed computation in a device or environment if it could be elsewhere. The
reason for placing computation at a specific location is either to process data
from sensors, to control actuators, or both. S ensors measure a physical phe-
nomenon (e.g., temperature or linear acceleration) and transduce that sensed
phenomenon into a signal that can be digitized, such as a voltage. Some sen-
sors output these voltages directly, in which case a system design must use
an analog to digital converter (ADC) to digitize its value. Other sensors have
integrated ADCs, in which case the sensor can make sensed values available
to a microcontroller already digitized. Most often, sensors which output dig-
ital data use the SPI or I2C communication interfaces
9
. In the FRDM-KL03
9
SPI and I2C define both
an electrical interface (e.g.,
a fixed number of wires
and their roles, whether
the buffers driving pins are
open-drain or push-pull) as
well as a logical or protocol
interface (what sequences
of voltages or bit values
to use to achieve a given
communication operation).
and FRDM-KL05 development platforms, the microcontroller is connected to
a MMA8451Q 3-axis accelerometer over an I2C interface. The warmup ex-
ample provided as part of Coursework item #2 implements the software to
communicate with the accelerometer, building on routines in the Freescale
KSDK. We will discuss sensors and measurement uncertainty in Topic
2 and
will discuss I/O interfaces such as SPI and I2C in Topic
9.
foundations of embedded systems 11
1.4 Power Dissipation in Embedded Systems
Many embedded systems operate in conditions where they could be plugged
into the electrical power grid. But most embedded systems operate in en-
vironments which are either mobile (e.g., a wearable fitness tracker), are
stationary but are far away from the electrical grid (e.g., a sensor tracking
wildlife in a game reserve
10
or monitoring the ecosystem around trees in a
10
Juang et al.
2002.
forest
11
), or would be otherwise cumbersome (e.g., retrofitting sensors onto
11
Tolle et al. 2005.
a bridge). Across most applications of embedded systems therefore, it is im-
portant to minimize how much energy sensors, processors, and other system
components use. Minimizing energy use could allow a system to run for
years off a single coin cell, or indefinitely (in principle) of energy scavenged
from photovoltaics or from vibration energy harvesters
12,13,14,15
.
16
12
Raghunathan et al.
2005.
13
Jiang, Polastre, and
Culler
2005.
14
Paradiso and Starner
2005.
15
Park and Chou
2006.
16
Roundy, Wright, and
Rabaey
2003.
For a system operating off a coin cell battery such as a CR2032 coin cell,
which have typical capacities of 230 mAh, the total theoretical energy avail-
able in the battery is about 900 J. In practice, you will rarely be able to ex-
tract this full capacity from a battery. There are many practical limitations
to how much of the theoretical energy stored in an energy source such as
an electrochemical batter y you can extract. These limitations include leakage
currents and battery self-discharge, equivalent series resistances (ESR) of bat-
teries which lead to resistive losses when drawing a current from the battery,
and more. The energy which you do extract from a battery is used to do
work and is dissipated as heat. For a low-power device running off a coin
cell, this heat will typically not be an issue of great concern. Figure
1.6(a–c)
show thermal images of several embedded systems: a system based on an
ARM Cortex-A8, a system based on an Intel Atom, and a system based on
the KL03, respectively.
17
17
Stanley-Marbell and
Cabezas
2011.
(a) TI DM3730 ARM
®
(Beagleboard) plat-
form.
(b) Intel Atom
D510 platform.
(c) Peak: BMX055 sensor after repeated accesses.
Figure 1.6: Representative
thermal imaging maps
(position and temperature
for 14,400 measurement
points) for several embed-
ded computing platforms.
You will get firsthand experience measuring power dissipation in embed-
ded systems using a software-controlled current measurement system during
12 phillip stanley-marbell
Coursework item #3, where you will evaluate the energy use of a small or-
ganic light-emitting diode (OLED) display.
What are the parameters that control power consumption if you wish to
improve the battery life of an embedded system? Most of the integrated
circuits (ICs) you will find in modern embedded systems are made using
a complementary metal oxide semiconductor (CMOS) process. Throughout
this course, when talking about transistor properties, we will generally im-
plicitly be referring to digital CMOS circuits rather than analog circuits. We
will assume, for example, that a circuit is part of a microcontroller or micro-
processor or other digital logic operating at some clock frequency f
clock
.
Power consumption in CMOS consists of two primary components: dy-
namic power consumption which occurs when transistors switch state of their
outputs, and leakage power consumption which occurs even when transistors
are not switching their outputs between states.
The dynamic power consumption for a transistor operating at supply volt-
age V
supply
, with a load capacitance C, and whose output changes for some
fraction sw of cycles of a clock running at frequency f
clock
, is given by
P C · V
2
supply
f
clock
· sw. (1.1)
Figure 1.7: Reduction of
supply voltages across
process technology nodes.
Because the dynamic power dissipation depends on the square of the sup-
ply voltage V
supply
, one of the most effective methods of reducing power
consumption in CMOS is to reduce the supply voltage. Over the years, semi-
conductors have therefore been designed to operate at ever lower voltages,
as Figure
1.7 shows.
18
The lower limit to how much supply voltage can be
18
Stanley-Marbell, Ca-
parros Cabezas, and
Luijten 2011.
reduced depends on the threshold voltage of the implementation process
19
.
19
Ignoring, for now,
subthreshold and near-
threshold circuits.
In Equation
1.1, the parameters V
supply
and f
clock
, which both appear, are
not independent. Let α be a parameter that depends on the implementation
process technology, and let V
t
be the threshold voltage of the implementation
process technology, then,
f
clock
V
supply
V
t
α
V
supply
. (1.2)
Even though these relationships are ostensibly for a single transistor, they
also hold for the large collections of transistors which make up an integrated
circuit such as a microcontroller, microprocessor, or the digital component
of a sensor. Figure
1.8 shows examples
20
of the relationship of Equation 1.2
20
Stanley-Marbell
2015.
for several processors. These plots of maximum operating frequency versus
supply voltage are traditionally referred to as shmoo plots.
When the transistors in a microcontroller or sensor are not switching and
dissipating dynamic power, they may still consume power due to leakage
paths through the transistor gate, or from the transistor’s source to drain.
foundations of embedded systems 13
ì
ì
ì
ì
ì
ì
ì
ì
ì
ì
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ò
ô
ô
ô
ô
ô
ô
ô
ô
ô
ô
ô
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
í
0
1
2
3
4
5
6
10
7
10
8
10
9
Supply Voltage, V HVoltsL
Frequency, f
max
HHzL
Α=1.11, Σ
0
=0.32
1993, WP2.2
Α=1.21, Σ
0
=0.53
1996, SP22.1
Α=1.71, Σ
0
=0.11
2000, WP25.3
Α=1.09, Σ
0
=0.46
2006, 22.5
Α=1.28, Σ
0
=0.41
2008, 13.1
Α=3.61, Σ
0
=0.21
2011, 7.5
é
é
é
é
é
é
é
é
é
é
é
é
é
é
é
é
á
á
á
á
á
á
á
á
á
á
á
á
á
õ
õ
õ
õ
õ
õ
õ
õ
õ
õ
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
ø
0
1
2
3
4
5
6
10
7
10
8
10
9
Supply Voltage, V HVoltsL
Frequency, f
max
HHzL
Α=1.00, Σ
0
=0.4
1986, WPM9.5
Α=1.63, Σ
0
=0.23
1999, TP15.3
Α=2.70, Σ
0
=0.19
2012, 3.6
Α=1.42, Σ
0
=0.25
2001, 15.4
Α=1.00, Σ
0
=0.44
2005, 10.3
Α=1.29, Σ
0
=0.35
1991 FP15.3
Figure 1.8: Empirical
data from voltage-versus-
frequency characterizations
(points) and fits to Equa-
tion
1.2 (lines), for several
large digital designs
published in ISSCC (1986
2012). The publication
dates and session/paper
IDs are listed next to each
curve. The curves are sep-
arated into two plots for
readability.
Let q be the electron charge, let V
gs
be the gate to source voltage, let V
t
be the threshold voltage, let T be the temperature of the transistor and let
k
B
and K
leak
a
be the Boltzmann constant and a process-dependent constant
respectively. Then, we can model the leakage current I
leak
of a CMOS circuit
as
I
leak
e
q·(V
gs
V
t
)
K
leak
a
·k
B
·T
!
. (1.3)
As Equation
1.3 shows, the leakage power consumption depends exponen-
tially on temperature. Circuits operating at higher ambient temperatures will
therefore have higher leakage power consumption.
There are many other factors that affect power dissipation in the microcon-
trollers and sensors that make up a typical embedded system. These factors
include the mode of operation (e.g., sampling rate) for sensors, the states of
I/O pins, and the chemistries of the specific passive devices such as capaci-
tors used for purposes such as power supply decoupling
21
. You can typically
21
These lead to different
leakage currents
get a reasonable estimate of the first order variation in power dissipation as
a result of actions of software controlling a system by reading through the
datasheet of the components of the system. Appendix
1 gives a brief guide
to effectively navigating datasheets.
1.5 Exercises
What is the difference between a processor and a microcontroller?
What microcontroller will we be using in this course?
How do we load programs into the memory of the microcontroller we will
be using in this course?
What does the phrase “running over bare metal” usually refer to in com-
puting systems in general?
Why does power dissipation in embedded systems matter?
14 phillip stanley-marbell
How does power dissipation in CMOS vary with frequency?
Does the power dissipation of a CMOS circuit vary with temperature?
What is the relationship?
1.6 Highlights from the Rest of the Course
By the end of this course, you should have gained a good grounding in the
theory and practice of designing and analyzing computing systems that inter-
act with the physical world. These “embedded” computing systems are ever
more common: It is now common to own a toothbrush that may have a mi-
crocontroller in it to control the brush pattern change indicators, to monitor
the battery level to alert you to charge it, and to control the charging pro-
cess. And, ever more such embedded systems are now gaining the capability
to communicate with each other and to connect to the Internet, enabling an
“Internet of things” (IoT).
Throughout this course, we will strike a balance between fundamental con-
cepts and practical engineering knowhow and insights. During the course,
you will develop an understanding of how things work. By the end of the
course, you should be well equipped to design engineering solutions to prac-
tical problems and to develop new ideas that could be the foundation for a
research project or a new product.
As we next highlight the topics that will be covered in the remaining top-
ics, start thinking of ideas for what you might want to do for the course
individual final project. The best ideas are those that you think should be
possible, but for which you don’t see exactly how to achieve them. Choose or
design a project which you will be excited to work on. Use this opportunity
to push yourself beyond what you could do on your own outside this course.
Our next session
22
, Topic
2, will cover fundamentals of the role of uncer-
22
Section 0.4 outlines the
relationship between the
topic numbering and the
order in which a course
using this material might
proceed. The ordering
in what follows is a rec-
ommended ordering for
covering the material and
is the ordering used in the
University of Cambridge
course 4B25: Embedded
Systems.
tainty in measurements of physical signals and will show how to quantify
measurement uncertainty for a given sensing system. We will study the dif-
fering roles of precision, accuracy, reliability, and measurement uncertainty
in embedded systems. We will explore how several common sensors oper-
ate and how this affects the noise in their outputs and the uncertainty of
measurements made with them. And, we will see how to analyze the prop-
agation of uncertainties through computations. Do you know the principles
of operation of all common sensors used in embedded systems? Can you
numerically quantify measurement uncertainty and noise in outputs given
a system design? Can you propagate measurement uncertainties quantified
as standard deviations through a sequence of arithmetic operations on mea-
surements with those associated uncertainties? Can you derive the method
for propagating those uncertainties from first principles? What is the fun-
foundations of embedded systems 15
damental property of a transistor that makes it possible for everything from
microcontrollers and sensors, to microprocessors, to operate in the inevitable
presence of manufacturing process variations and electrical noise? If you an-
swered “no” or “not sure” to any of these questions, you will not want to
miss Topic
2.
In Topic 4, we will cover C and ARM assembly programming in embedded
systems. Are you familiar with linker script or linker command files? Are you
familiar with ARM assembly language or with any other assembly language?
Are you familiar with the Cortex-M 0 instruction subset of the ARM ISA?
Would you have no trouble writing a program in which one of the routines is
in assembler and the rest in C? Are you familiar with the STABS debugging
format? Do you know what ANCI C trigraphs are? What about the special
role of crt0.s in the linker and of the function main in C programs? If you
answered “no” or “not sure” to any of these questions, you will not want to
miss Topic
4.
We will focus on designing communication subsystems in Topic 9. We will
discuss the required electrical circuit support between a collection of I2C- or
SPI-interfaced sensor integrated circuits and an ARM Cortex-M0 microcon-
troller. We will discuss I/O principles and I/O practice with I2C, I3C, SPI,
MIPI DSI, and MIPI CSI. You will need the material covered in Topic
9 for
Coursework item #3.
We will consolidate the ideas introduced in the first half of the course
with a case study of the TI SensorTag platform in Topic 11. The TI Sen-
sorTag platform is an embedded system with multiple sensors interfaced to
by a processor and with a Bluetooth Low Energy (BLE) radio interface for
communication.
Topic
7 will introduce field-programmable gate arrays (FPGAs). It will
provide an introduction to the Verilog hardware description language for cre-
ating digital hardware designs, will provide an introduction to the Yosys/ices-
torm open-source Verilog synthesis and FPGA development tools, and will
provide an introduction to an important family of FPGAs that are designed
specifically for low-power embedded systems: the iCE40 family of low-pincount
low-power FPGAs. Unlike other more popular FPGAs, the primary target
usage of the iCE40 FPGAs are in energy-constrained embedded systems con-
sisting of processors and sensors.
Continuing our transition from sensors, to I/O, to computation, to other
digital logic accelerators, we will focus on displays (specifically, those made
from organic light-emitting diodes (OLEDs)) and on the human visual sys-
tem’s perception of color, in Topic
12.
In Topic 13, we will take an new perspective on embedded systems in
which we look at them as systems in which signals constitute dimensions
16 phillip stanley-marbell
in a multi-dimensional space, and measurements constitute points in the re-
sulting generalized coordinate space. Given this context, we will introduce and
explore the concept of invariants induced on signals by the laws of nature or
by the design of the system in which those signals are measured. We will
review the concepts of Lagrangians, Hamiltonians, the Euler-Lagrange equa-
tions, Noether’s theorem, and recent research on inferring Lagrangians and
Hamiltonians from sensor data.
In Topic
10, we will study the networking of embedded systems using
wireless communication. We will study the parts of a typical radio commu-
nication interface transceiver, medium-access control (MAC) protocols and the
reasons and challenges of their implementation in software. We will outline
several new competing wireless communication technologies that are used in
a number of different low-power sensor-driven systems, including Bluetooth
(BT), Bluetooth Low Energy (BLE), IEEE 802.15.4 and Zigbee, LoRa, NB-IOT,
and Sigfox.
In the final week, we will shift our focus to practical engineering and im-
plementation techniques. In Topic
11, we will dive into a detailed case study
of the design and implementation of the Warp multi-sensor research hard-
ware platform, starting from the motivation and design goal and then pro-
ceeding from from schematic capture to printed circuit board layout, board
stackups, and the process of getting printed circuit boards professionally
assembled by a contract assembly facility. In the final topic of the course
(Topic
15), we will cover further practical issues in implementing the hard-
ware and software for custom-designed embedded systems. These issues
range from component availability, prototyping using evaluation boards, and
software bringup on new (and buggy) hardware. The syllabus for the course
based on these notes at the University of Cambridge is available online at this
link.
1.7 Project Ideas
You are free to suggest your own project ideas. Examples of project ideas
include:
1. Uncertainty propagation in algorithms (software-only project). Topic
2
will introduce methods for propagating uncertainty from the inputs of
an arithmetic operation (e.g., addition, multiplication, exponentiation) to
the arithmetic operation’s result. When sensor data serves as the input
to signal processing applications, we can in principle propagate measure-
ment uncertainty from the inputs of a sensor data processing algorithm
all the way to its final result. This project will modify an emulator for a
microcontroller to implement uncertainty propagation using the methods
foundations of embedded systems 17
introduced in Topic
2.
2. Hardware and firmware design of a 3D sensor for a miniature drone:
Design a new 3D sensor using an array of VL53L0X time-of-flight ranging
sensors paired with a KL05 processor that can be used as a 3D sensing”
add-on board for CrazyFlie drone.
3. Design the hardware and firmware for a Water quality monitor using
an array of different colors of LEDs paired with photodetectors, or using
a photoplethysmography (PPG) sensor such as the OSRAM SFH750, or
some combination of these.
4. Detecting structural properties using accelerometer data: Implement al-
gorithms for detecting structural properties of any structure to which the
FRDMKL05 board with coin-cell battery socket is attached, by performing
signal analysis of accelerometer data. This should let you, for example,
detect if the platform is attached to car or attached to a walking human
or attached to window or attached to a wooden table or attached to steel
table.
5. Implement a Cortex-M0 emulator based only on datasheet information
(software-only project). You will integrate your implementation into the
Sunflower simulator
23
and will have the option of either implementing
23
Stanley-Marbell and
Marculescu
2007.
all the peripherals of a particular Cortex-M0 implementation (e.g., the
KL05), or you can choose to reuse the SH3 peripheral behavior already
implemented in Sunflower. You will build on a partial implementation of
Cortex-M0 support implemented in a project from a previous year.
6. Implement an OLED interface in the iCE40 FPGA with power-saving
color transformations implemented in hardware.
7. Implement an ADC with value-deviation-bounded approximate quan-
tization in the iCE40 FPGA.
8. Implement a neural network with lossy inter-neuron communication in
the ICE40 FPGA, building on the open-source Marlann neural network
accelerator.
1.8 Summary
Embedded systems are computing systems that interact with the physical
world. They are often embedded or deployed in environments where they
are used for tasks different from a traditional interactive desktop computer,
18 phillip stanley-marbell
laptop, or server. Embedded systems are typically deployed with the objec-
tive of interacting with the physical world through sensors such as tempera-
ture sensors or accelerometers, or controlling actuators such as servos or dis-
plays. Because embedded systems often bridge the physical world and cyber
world, they are sometimes also referred to as cyberphysical systems. And,
when they are networked to each other and to the Internet, the collection
of networked computing and sensors is often referred to as the Internet of
Things. This course will introduce the fundamental theory and engineering
practice of designing and evaluating computing systems that interact with
the physical world, with humans, and which may be networked.
1.9 Reading
Revisit the questions in Section
1.1.5. If there are questions which you still
cannot answer after reading this chapter, make a note of which part of the
later parts of the course cover that topic.
1.10 Relevant Books Available in the Engineering Library
1. Embedded Systems Dictionary, ISBN: 978-1578201204.
2. The Art of Designing Embedded Systems, Second Edition, ISBN: 978-0750686440.
foundations of embedded systems 19
1.11 The Muddiest Point
Think about the following two questions and submit your responses through
this
link.
1. What was least clear to you in this chapter? (You can simply list the section
numbers or write a few words.)
2. What was most clear to you in this chapter? (You can simply list the
section numbers or write a few words.)