Embedded systems¶
Learning goals:
After studying this material, you will known what are embedded systems, what is the meaning of hardware-oriented programming, what are its main characteristics, and how embedded devices are programmed.
Embedded systems - Why?¶
Embedded system is a device or a system that is controlled by a computing device and specifically made to perform a dedicated task. In this kind of systems, usually users are aware of the computer device inside of it, even though its existence can be easily deduced. Embedded systems are widely used today in various application areas:
Home appliances, entertainment electronics, smartphones, air conditioning, elevators, …
- Cars, airplanes, trains, … (multiple internal embedded systems)
- Health technology: hospital equipment, remote diagnostics, heart rate monitors, …
- Industrial automation: robotics, process control and monitoring, …
- Space technology: satellites, probes, …
- Future (and even the present): smart transportation, intelligent environments, wearable technology, …
Hardware-oriented programming, refers to computer programming where programs are developed very close to the computer's hardware, meaning its physical components and parts. This can involve directly controlling the electronic signals that enable different components to function. Nowadays, however, these functionalities are abstracted into layers and existing libraries, making embedded programming significantly easier, as you'll see later in the course.
Embedded systems at work.. and as a hobby. Easier than it seems!
Internet of Things¶
In the course, we operate in the environment of theIoT. IoT is a global ecosystem of interconnected devices and objects where billions of networked things and devices communicate with each other via the Internet. Nowadays, the Internet of Things has two main perspectives.
- Consumer and Societal Perspective: The Internet of Things enables new applications in the field Ubiquitous Computing/Smart Environments/Ambient Intelligence: smart environments, services, and applications for consumers, businesses, and society. Individual devices and applications collect data about their environment and operations, becoming part of an ecosystem. Examples include real-time monitoring of urban events such as traffic flow, energy consumption in cities/homes, tracking human activities (health technology), and remote control of home appliances.
- Industrial Perspective: Another significant application area for IoT solutions is Industrial Internet of Things a pillar of Industry 4.0. Here, embedded systems are used at the level of individual system components. For example, they automate entire factory operations, monitor production processes, and optimize them using Big data. This can involve for example managing energy consumption or logistics. As a result, a factory floor may have (tens of) thousands of interconnected embedded systems via various networks.
You can see a short introduction video
The components of an embedded device¶
An embedded device is a resource-constrained microcomputer designed and functioning specifically for a particular purpose, in contrast to a general-purpose workstation like a home PC. Compared to a PC, an embedded device typically includes only the essential components necessary for its intended use.
The operation of an embedded device generally involves receiving inputs (such as sensor data) related to the behavior of a larger system (e.g., a washing machine or a car) or environmental observations (e.g., greenhouse temperature). The device's program then responds to these inputs based on its programmed logic. For instance, it might analyze simple events (such as exceeding an allowed temperature) based on data from sensors. Often, the program also generates an output (e.g., controlling a larger device using an actuator, like adjusting greenhouse ventilation).
The operation of an embedded device generally involves receiving inputs (such as sensor data) related to the behavior of a larger system (e.g., a washing machine or a car) or environmental observations (e.g., greenhouse temperature). The device's program then responds to these inputs based on its programmed logic. For instance, it might analyze simple events (such as exceeding an allowed temperature) based on data from sensors. Often, the program also generates an output (e.g., controlling a larger device using an actuator, like adjusting greenhouse ventilation).
The most visible part of an embedded device for the user is the user interface. Inputs to the device are provided through integrated physical components such as switches (buttons) or a control panel (touchscreen). The device produces responses either on a display (small LCD screen) or through audio signals (speaker) or light indicators (LEDs). However, depending on its purpose, an embedded device may not necessarily have a user interface—for example, when it is integrated into the control system inside a car.
The role of the microcontroller in the embedded device is to handle data processing, acting as the central unit or processor. It executes the program designed for the device.
The role of the microcontroller in the embedded device is to handle data processing, acting as the central unit or processor. It executes the program designed for the device.
The device may also include mass storage, such as an external SD memory card or non-volatile EEPROM memory for long-term data storage. Of course, an embedded device requires a power source, which, in a mobile device (like a pedometer), is typically a battery or rechargeable cell.
Designers of these devices select the necessary components, considering their physical size, electronic and physical characteristics (sensor measurement range), interfaces, power consumption, programming, and other factors. They create an embedded device where external and internal components are connected to create a functional product. In this video you can see how an embedded device works.
Designers of these devices select the necessary components, considering their physical size, electronic and physical characteristics (sensor measurement range), interfaces, power consumption, programming, and other factors. They create an embedded device where external and internal components are connected to create a functional product. In this video you can see how an embedded device works.
Microcontroller¶
A microcontroller (also known as a MCU) refers to a single integrated circuit that includes both the CPU and other functional electronic components. The microcontroller in an embedded device corresponds to a computer's microprocessor, but its features are trimmed compared to processors found in home PCs, for example. However, a MCU contains all necessary peripherals necessary to run the computing device including clock, memory and other peripherals (e.g. UART). A microcontroller operates at a low clock frequency and has limited memory, which is further divided into separate program memory (also known as read-only memory, ROM, e.g., Flash memory) and the working memory (also known as random-access memory, RAM) used by programs. Devices often have various types of memory tailored to their specific purposes.
In modern embedded devices, such as smartphones or cars, there are multiple microcontrollers, each performing its own task. For instance, one MCU handles the device's operational logic, another focuses on wireless data transmission, and a third controls the display. This division of labor among microcontrollers enhances the efficiency of the device and its applications by distributing the program's workload across several microcontrollers. Notably, wireless data transmission is a resource-intensive operation in embedded devices, and using a single microcontroller might cause other functions to pause during data transfer
In modern embedded devices, such as smartphones or cars, there are multiple microcontrollers, each performing its own task. For instance, one MCU handles the device's operational logic, another focuses on wireless data transmission, and a third controls the display. This division of labor among microcontrollers enhances the efficiency of the device and its applications by distributing the program's workload across several microcontrollers. Notably, wireless data transmission is a resource-intensive operation in embedded devices, and using a single microcontroller might cause other functions to pause during data transfer
The embedded device of the course¶
The embedded devices used in the course are:
- Texas Instruments' Simplelink SensorTag (which we refer to as SensorTag), offering an excellent view into the current IoT world with its pre-integrated components!
- Raspberry Pi Pico W (affectionately known as "Pico"), which provides an excellent perspective on the current IoT world, especially when used with its extension board!
SensorTag¶
At the heart of the device is a 32-bit microcontroller, which has an integrated wireless radio and its own secondary microcontroller for data transmission. The circuit board of the device is also connected to about ten motion and environment measuring sensors (accelerometer, gyroscope, temperature, light, humidity, and pressure sensors, as well as a magnetometer, compass, and microphone). On the same circuit board, there are also push buttons, LEDs, and a small speaker. External additional components for the device include, for example, a black-and-white LCD display.
The radio integrated into the SensorTag offers several different technologies for wireless data transmission, of which we will use 6LoWPAN technology on the 2.4GHz frequency band in the course (you don't need to know the details of this technology for the course). The teaching staff has implemented a ready-made library for data transmission between devices.
The SensorTag operates (when properly programmed) on a coin battery for up to weeks, thanks to the carefully optimized power consumption of the microcontroller and peripheral components.
As an example, the SensorTag and integrated LCD display could function as a smartwatch!
Raspberry Pi Pico W¶
At the heart of the device is a modern RP2040microcontroller with dual cores. The Pico also features an integrated wireless radio and two microcontrollers that handle data transfer via Wi-Fi and Bluetooth. Additionally, the device's extension board includes several sensors for measuring motion and environmental factors (such as acceleration, orientation, temperature, light, humidity, and a microphone). On the same circuit board, you'll find a button, an LED, and a small speaker. The extension board can also accommodate a black-and-white LCD display.
The integrated radio in the Pico supports various technologies for wireless data transfer. In this course, we'll focus on Wi-Fi technology (you don't need to know the details of this technology right now, though). The course staff has already implemented a ready-made library for wireless data transfer.
The integrated radio in the Pico supports various technologies for wireless data transfer. In this course, we'll focus on Wi-Fi technology (you don't need to know the details of this technology right now, though). The course staff has already implemented a ready-made library for wireless data transfer.
When properly programmed, the Pico can run on a coin cell battery for weeks, thanks to its minimal power consumption from the microcontroller and peripheral components.
Below is a diagram of the Pico and its pin layout (we'll revisit this later in the course).
Embedded system vs. PC¶
Compared to general-purpose PC-workstations, embedded system has been developed to work only for a distinct, modest use case. In these applications, the need for computational power, memory and features of the computer is typically minimal. Consequently, it is cost effective to use an embedded device instead of general-purpose PC hardware, which generally can work with low-performance components, which in turn reduces the manufacturing cost of such device. For example, it would be inefficient to use a modern PC to just remotely open a garage door.
Example: The differences between PC and an embedded device from hardware perspective.
Typical PC | Embedded device | |
Clock frequency | 2-5GHz | 16Mhz - 1GHz |
RAM-memory | 8-64GB | 2kB - 2GB |
32kB - 128MB Flash-program memory | ||
Processor | 64bit | 8bit / 16bit / 32bit / Some 64bit |
Mass memory | 256GB - 2TB (SSD/HDD) | Peripheral device, for example an SD-card |
128B - 16MB non-volatile EEPROM/FRAM memory | ||
Plugins | Integrated sound card | Small buzzer, GPIO pins |
Graphics card | Small LCD/OLED screen or e-paper display | |
Keyboard and mouse | Button, slider, or a touch screen |
In fact, modern PC's use peripheral devices that run their own internal embedded system. Examples of devices like this are a network card or a printer
The design and implementation of an embedded device¶
Due to the wide range of application areas, use cases, and requirements, designing and implementing embedded devices requires expertise from multiple fields, making it a collaborative effort. In essence, familiarity with the domain - such as medicine or process industries - and understanding the operational context is essential. Additionally, expertise in areas like electronics, computer engineering, software engineering, telecommunications, automation, and even mechanics is typically necessary. Furthermore, when designing devices for consumer markets, experts in user interface design and industrial design also play a crucial role.
From the perspective of computer and software engineering, an embedded device involves designing and implementing the interface between hardware and software, which consists of various electronic and mechanical components. Depending on the application, real-time performance, the predictability of system behavior and responsiveness, the coverage of functions relative to the expected application area are critical. Moreover, fault tolerance and handling error situations are important, as embedded systems often operate autonomously without human intervention. To support the development of embedded systems, specific software engineering and production methods, as well as programming environments, have been created. These often include simulators and/or emulators to verify program correctness during development before prototypes are even deployed to the actual device.
While we won’t delve into software engineering specifics in this course, when programming, we will follow event driven paradigm for our embedded systems. The central idea is to create a program that responds appropriately to events generated by peripheral components (such as button presses, new sensor readings, timing signals, wireless messages, etc.). Event-driven approaches are commonly used in software development, including user interface implementations for web applications.
Running programs¶
There are significant differences in the execution of programs on a PC and an embedded device. In workstations, programs always run on top of an operating system (such as Windows, Mac OS X, Linux, …), but in embedded systems, there are options based on the purpose and choices made during the design phase.
If an embedded device has sufficient resources (such as smartphones) to run an operating system, it is typically a stripped-down version of a PC operating system (for example, various real-time Linux distributions). It provides minimal services for program execution and access to hardware resources.
Sometimes, there is no operating system in embedded devices because the purpose is so simple that it doesn't require operating system services. In such cases, embedded programs are typically implemented on top of firmware. When the device starts up, the firmware initializes first, and other programs start afterward. The firmware connects the components of the embedded device into a functional computer and provides a low-level programming interface for working with components, typically including device drivers and higher-level abstractions to facilitate programming. A well-known example of embedded firmware is the user-friendly Arduino platforms.
When programming embedded systems, the firmware can be compiled as part of the embedded program, or the firmware might already be present in the device's program memory, with only the developer's program being loaded during the programming process. In contrast, in the PC world, the BIOS (or more recently UEFI) primarily serves as low-level firmware that initializes hardware during the boot process and hands control over to the operating system. BIOS/UEFI services are typically not involved in programming tasks once the operating system is running. Instead, the operating system and its drivers handle hardware interactions, and programming is done at the software level using system calls when the software needs to access certain piece of hardware (e.g memory, hard drive, network card). More on that in the Computer Systems course section, for all students who are taking the second part of the course.
It's also possible to implement an embedded application without firmware (so-called bare-metal), but in that case, the programmer needs to create the necessary peripheral interfaces and drivers, including initialization and setup. In bare-metal, programmer needs to control GPIO pins and different registers of the MCU. This naturally requires a deeper understanding of the microcontroller and the electronic operation and control of peripherals. In order to program bare-metal it is necessary to go carefully through the datasheet of the microcontroller or sensor developer is using.
In this course, we'll be creating programs for the Pico and SensorTag on top of a real-time operating system, using manufacturer libraries for assistance. The SDK (Software Development Kit) provided by manufacturers offers pre-implemented services, interfaces, and drivers, so we don't need to create them ourselves—only the functionality required by the application.
Programming an embedded device¶
When a microcontroller in an embedded device starts up, it automatically begins by executing the firmware. Guided by the firmware, the device initializes itself and its components. After this initialization, the application program stored in the program memory is executed. The application continues to run until the device's power is cut off or a fault occurs. Typically, the program in an embedded device is not changed once it's loaded during manufacturing. Occasionally, there may be a need to update the program, but that can be costly due to reinstallation or even product recalls. However, exceptions exist, especially in devices with sufficient resources to run more advanced operating systems (such as smartphones), allowing third-party programs to execute more freely.
Even today, embedded systems are often programmed using the C programming language (and also its more modern counterpart, C++). Although C was developed in the 1970s, it remains popular for writing efficient, low-level code specifically for embedded systems. C is also a permissive language, allowing programmers to perform many low-level tasks that might not be possible in other languages. Nowadays, RUST is taking traction. However, it is not clear if it can overshadow C in embedded devices.
Programming for embedded devices typically occurs in a PC or workstation environment using development tools provided by the device manufacturers (often available for free). Unlike interpreted languages, embedded systems are generally not programmed interactively, and code cannot be modified on the fly as in, for example, Python interpreters. The process of programming an embedded device involves several steps:
- The C program is first compiled using a C compiler on the workstation, translating it into a format that the chosen microcontroller can understand, to its https://en.wikipedia.org/wiki/Machine_code.
- The program is then linked with firmware (or a user interface) libraries and drivers, resulting in an executable program. (Due to resource constraints, only necessary drivers are included.)
- The combined program is written (flashed) to the embedded device's program memory using a separate programming tool.
- During development and testing, the program's execution on the device is controlled using a separate Debugger. Debuggers allow real-time examination of code, program state, and memory contents.
In the picture below, the SensorTag's programming and debugging device (visible circuit board) that we will use in the course. The device is connected to the PC via a USB connector.
In the course, SensorTag is programmed in the C language using the manufacturer's development environments, primarily in the Code Composer Studio. We will programme the Pico using the C language within a Visual Studio Code-based development environment. We'll leverage the Pico SDK's libraries and drivers to implement our programs.
Detailed instructions for using the software and environment will be covered in the course's lab exercises, so hold off on any installations for now.
Challenges¶
When designing and programming embedded systems, it’s essential to consider several factors, including:
- Microcontrollers often have restricted computational capacity, even though hardware may have strict timing requirements (e.g., in factory applications).
- Small memory sizes limit both computation and data transfer capacity.
- Embedded systems have limited communication with peripheral devices.
- Some devices lack an operating system, while others use highly trimmed-down Real Time Operating Systems
- For battery-powered or battery-operated embedded devices, optimizing power consumption is crucial during design.
We'll delve into these topics in more detail in the course material...
To conclude¶
Embedded system hardware platforms are available for hobbyists to use at home from various major microcontroller manufacturers, typically costing a few tens of euros. The most well-known platform is probably the hobbyist-friendly Arduino, which initiall was based on 8-bit microcontrollers from ATmel but now uses a 32-bit ARM chip. Arduino provides a high-level programming language based on C++, and the goal is to make Arduino programming accessible even for those with limited programming experience. For example, Arduino is used in digital media education. While Arduino is too simplified for our course, having knowledge of its programming can still be beneficial.
It's important not to confuse the Pico with other more complex devices offered by Raspberry Pi (such as the Raspberry Pi 5). These devices have extensive features and resources (for instance, the Raspberry Pi 5 can have up to 8GB of RAM!), making them more like Single Board Computer. Raspberry Pi devices often run Linux operating systems, which would be too heavy for Arduino. Some people don't consider the Raspberry Pi a true embedded system, but it can certainly be embedded in various environments of ubiquitous computing, much like Arduino.
External accessories have been released for the SensorTag through the DevPack interface, which are also openly available online. This means that anyone can create their own additional components for the device, for example, students as part of their bachelor's thesis. You can create also
hats or extension boards
for the Pico. Just need to follow the pinout.Additional bibliography¶
Refer to the course book Embedded Systems
Give feedback on this content
Comments about this material