Hands-On RTOS with Microcontrollers (eBook)
570 Seiten
Packt Publishing (Verlag)
978-1-80324-304-7 (ISBN)
This updated edition of Hands-On RTOS with Microcontrollers is packed with cutting-edge content to help you expand your skills and stay ahead of the curve with embedded systems development. Written by senior engineers with decades of experience in embedded systems and related technologies, it covers the role of real-time OSs in today's time-critical applications, and it covers FreeRTOS, including its key capabilities and APIs. You'll find detailed descriptions of system design, hands-on system use, the hardware platform (dev-board, MCU, and debug-probe), and the development tools (IDE, build system, and debugging tools).
This second edition teaches you how to implement over 20 real-world embedded applications, using FreeRTOS's primary features. The chapters include example programs on GitHub, with detailed instructions. You'll create and install your own FreeRTOS system on the dev-board (purchased separately), and set up an IDE project with debugging tools.
An ST dev-board is used with the book, and it is purchased separately (STM32 Nucleo-F767ZI - the dev-board is not required to read and understand the book).
By the end of this book, you'll have the hands-on skills to start designing, building, and optimizing embedded applications, using FreeRTOS, development boards, and debugging tools.
Gain the practical skills and insights you need to supercharge your embedded engineering journey by working with over 20 example programsKey FeaturesUnderstand and master RTOS concepts using the powerful STM32 platformStrengthen your embedded programming skills for real-world applicationsExplore advanced RTOS techniques to unlock innovative embedded solutionsAll formats include a free PDF and an invitation to the Embedded System Professionals communityBook DescriptionThis updated edition of Hands-On RTOS with Microcontrollers is packed with cutting-edge content to help you expand your skills and stay ahead of the curve with embedded systems development. Written by senior engineers with decades of experience in cybersecurity, operating systems (OSs), and embedded systems, it covers the role of real-time OSs in today's time-critical applications and FreeRTOS with its key capabilities and APIs. You'll find a detailed overview of system design (memory management), project design (MCU, IDE, and RTOS APIs), and hands-on system use as well as the system platform, dev-boards with an MCU and a debug probe, and development tools (IDE, build system, and source-code debugging). This second edition teaches you how to implement over 20 real-world embedded applications with the latest FreeRTOS features and how to optimize your code with dynamic analysis. The chapters include example programs on GitHub with detailed instructions. You ll create and install your own FreeRTOS system on the dev-board and set up an IDE project with debugging tools. With dozens of reference manuals listed, you ll always have ample resources for system development. By the end of this book, you ll have the hands-on skills to design, build, and optimize embedded applications using FreeRTOS, dev-boards, and modern debugging tools.What you will learnUnderstand RTOS use cases, and decide when (and when not) to use real-time OSUtilize the FreeRTOS scheduler to create, start, and monitor task statesImprove task signaling and communication using queues, semaphores, and mutexesStreamline task data transfer with queues and notificationsUpgrade peripheral communication via UART, USB, and DMA by using drivers and ISRsEnhance interface architecture with a command queue for optimized system controlMaximize FreeRTOS memory management with trade-off insightsWho this book is forThis book is for systems programmers, embedded systems engineers, and software developers who want to learn about real-time operating systems (RTOS) and how to use FreeRTOS in their embedded system design. A basic understanding of the C programming language, embedded systems, and microcontrollers is assumed. The book also includes hardware tutorials for systems programmers.]]>
1
Introducing Real-Time Systems
Real-time systems come in a wide variety of implementations and use cases. This book focuses on how to use a real-time operating system (RTOS) to create real-time applications on a microcontroller unit (MCU).
In this chapter, we’ll start with an overview of what an RTOS is and get an idea of the wide range of systems that can have real-time requirements. From there, we’ll look at some of the different ways of achieving real-time performance, along with an overview of the types of systems (such as hardware, firmware, and software) that may be used. We’ll wrap up by discussing how to choose an RTOS, when it is advisable to use an RTOS in an MCU application, and when it might not be necessary at all.
For readers who are not familiar with MCUs, tutorial information on MCUs can be found in Chapter 2, Introducing the Development Board.
In a nutshell, we will cover the following topics in this chapter:
- What is “real-time” anyway?
- Hardware and software roles in real-time systems
- Defining RTOSes
- Practical real-time systems
- Choosing an RTOS
What is “real-time” anyway?
Real-time systems are systems that have timing requirements. A real-time system is considered to fail when it doesn’t meet a timing requirement. How a timing failure is defined (and the consequences of a failed system) can vary widely. It is extremely important to realize that real-time requirements can vary widely, both in the speed of the timing requirement and the severity of consequences if the required real-time deadlines are not met.
Every real-time system is constrained in its ability to respond to events and/or signals. A system’s ability to respond to events and/or signals is referred to as the system’s bandwidth. For example, when designing a signal acquisition chain, the system’s bandwidth for each filter stage must be wide enough to pass through the desired signal in order to maintain the integrity of the signal. If the system’s bandwidth for the filters is not properly designed, the system will fail to provide the desired real-time response to certain input signals.
The system’s hardware and software both have limited bandwidth. All software executes on hardware that has limited resources. For example, the clock frequency of an MCU limits how many instructions it can execute in a given period of time. The rate of instruction execution is also limited by the MCU architecture, which determines how many clock cycles are required to execute each instruction. The ability of the software to respond to events in real time is affected by the algorithms used, the operating system (OS) used (if any), and the effective use of the OS’s features, such as multitasking and timing features.
The limitations of the hardware and software make real-time design both challenging and fun. Challenging, because the designer often has to look into the nitty-gritty of the MCU architecture, including the hardware peripheral registers and the assembly code instructions. But fun, from the satisfaction of understanding the intricacies of how the hardware works, and from being able to write software that takes advantage of it.
It is both a science and an art to balance these limitations and to understand the trade-offs between hardware and software in order to get to the end goal of a working real-time system.
The range of timing requirements
To illustrate the range of timing requirements that can be encountered, let’s consider a few different systems that acquire readings from analog-to-digital converters (ADCs).
Let’s first look at a lower-bandwidth control system. The control system is part of a soldering iron, and the control system maintains the tip’s temperature (as seen in Figure 1.1). The parts of the system we’re concerned with are the MCU, ADC, sensor, and heater.
The MCU is the brain of the control system. It is responsible for the following:
- Taking readings from a temperature sensor via the ADC
- Running a closed-loop control algorithm (to maintain a constant temperature at the soldering iron tip)
- Adjusting the output of the heater as needed
These can be seen in the following figure:
Figure 1.1: MCU-controlled soldering iron
A typical soldering iron would have pretty low bandwidth needs. For example, since the temperature of the tip doesn’t change very quickly, the MCU may only need to acquire 50 ADC samples per second (50 Hz). The control algorithm responsible for adjusting the heater (to maintain a constant temperature) may run at an even slower pace, perhaps 5 times per second (5 Hz).
While we are here, let’s take a quick look at the timing requirements of the ADC. Doing so will give us a feel for some of the time constraints we deal with when designing real-time systems. Figure 1.2 shows a common interface between an MCU and an ADC:
Figure 1.2: MCU with external ADC
The ADC asserts a signal to inform the MCU that the ADC has completed a conversion of the analog signal and that a digital value is ready for the MCU to read. The MCU must read the converted digital value, using the communication channel, before the next conversion takes place, or the result will be overwritten. The MCU has up to 20 ms to transfer the data from the ADC to internal memory before a new reading needs to be taken (as seen in Figure 1.3 below). The MCU also needs to be running the control algorithm to calculate the updated values for the heater output at 5 Hz (200 ms). Both of these cases (although not particularly fast) are examples of real-time requirements.
Figure 1.3: Free-running 50-Hz ADC
Now that we have looked at a lower-bandwidth control system, let’s consider that other control systems may require much higher bandwidth. For example, a network analyzer or oscilloscope may require reading an ADC at a rate of tens of GHz! The raw ADC readings will likely be converted into the frequency domain and graphically displayed on a high-resolution front panel dozens of times a second. To function properly, such a system requires significant data-processing bandwidth, and it must adhere to extremely tight timing requirements.
Somewhere in the middle of the possible bandwidth requirements, you’ll find systems such as closed-loop motion controllers, which will typically need to execute their proportional–integral–derivative (PID) control loops between hundreds of Hz to tens of kHz in order to provide stability in a fast-moving system. So, how fast is real-time? Well, as you can see from the ADC examples alone, it depends on the requirements.
In some of the previous cases, such as the oscilloscope or soldering iron, failure to meet a timing requirement results in poor performance or incorrect data being reported. In the case of the soldering iron, this might be poor temperature control (which could cause damage to components). For the oscilloscope, missing deadlines could cause erroneous readings, which is a failure. Too many inaccurate readings will cause the device to be viewed as unreliable, and sales will decline—all because a real-time requirement wasn’t being met consistently.
In other systems, such as the flight control of an unmanned aerial vehicle (UAV) or motion control in industrial process control, failing to run the control algorithm in a timely manner could result in something more physically catastrophic, such as a crash. In this case, the consequences are potentially life-threatening.
Thankfully, there are steps that can be taken to avoid all of these failure scenarios.
The ways of guaranteeing real-time behavior
One of the easiest ways to ensure that a system does what it is meant to do is to make sure it is as simple as possible while still meeting the requirements (some call this the KISS principle—Keep It Simple, Stupid!). This means resisting the urge to over-complicate a simple task. If a toaster is meant to toast a slice of bread, don’t put a display on it and make it tell you the weather too; just have it turn on a heating element for the right amount of time. This simple task has been accomplished for years without requiring any code or programmable devices whatsoever.
As programmers, when we encounter a problem, we tend to reach for the nearest MCU and start coding. However, some functions of a product are best handled without code at all (this is especially pertinent if a product has electro-mechanical components). A car window doesn’t really need an MCU with a polling loop to run, turning on motors through drivers and watching sensors for feedback to shut them off. This task can actually be handled by a few mechanical switches and diodes. If a feedback-reporting mechanism is required for a given system—such as an error that needs to be asserted in the case of a stuck window—then there may be no choice but to use a more complex solution. However, our...
| Erscheint lt. Verlag | 30.9.2025 |
|---|---|
| Sprache | englisch |
| Themenwelt | Informatik ► Programmiersprachen / -werkzeuge ► C / C++ |
| Informatik ► Weitere Themen ► Hardware | |
| Technik ► Elektrotechnik / Energietechnik | |
| ISBN-10 | 1-80324-304-X / 180324304X |
| ISBN-13 | 978-1-80324-304-7 / 9781803243047 |
| Informationen gemäß Produktsicherheitsverordnung (GPSR) | |
| Haben Sie eine Frage zum Produkt? |
Digital Rights Management: ohne DRM
Dieses eBook enthält kein DRM oder Kopierschutz. Eine Weitergabe an Dritte ist jedoch rechtlich nicht zulässig, weil Sie beim Kauf nur die Rechte an der persönlichen Nutzung erwerben.
Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belletristik und Sachbüchern. Der Fließtext wird dynamisch an die Display- und Schriftgröße angepasst. Auch für mobile Lesegeräte ist EPUB daher gut geeignet.
Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür die kostenlose Software Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür eine kostenlose App.
Geräteliste und zusätzliche Hinweise
Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.
aus dem Bereich