Review: Hands-On RTOS with Microcontrollers
Full disclosure: I was given a free copy of this book for evaluation.
Hands-On RTOS with Microcontrollers: Building real-time embedded systems using FreeRTOS, STM32 MCUs, and SEGGER debug tools by Brian Amos is an outstanding book. It lives up to its name, extremely hands-on and practical, taking you from knowing nothing about RTOS's (Real-Time Operating Systems) up to building real multithreaded embedded system applications running on real hardware.
It uses the ST Micro STM32 Nucleo-F767ZI development board (under $35 USD with shipping from distributors) to run all its examples, written in C and built with free downloadable tools that run on Windows, Mac, or Linux. Full source code for all examples is downloadable.
It isn't just for FreeRTOS. Every RTOS is a little different, each making slightly different design decisions, but fundamentally they all share the same concepts. This book provides a very practical fundamental grounding in the concepts, methods, and considerations for using a variety of RTOS's in a wide variety of applications, such as ThreadX, QNX, Micrium uC/OS, VxWorks, RTEMS, Keil RTX, embedded Linux, Zephyr, and others, as well as the CMSIS-RTOS and POSIX API's.
Amos does an excellent job of presenting concepts and background information, explaining the pros and cons of various options, and then showing how to use them. The pattern he uses is to start with polling in a bare-metal single-threaded application, progressing to ISR's (Interrupt Service Routines), DMA (Direct Memory Access), and then full RTOS multi-tasking.
He explains when each form is recommended or not recommended, costs, and benefits. He discusses the various tradeoffs to be made, which is a critical part of engineering. As he repeatedly points out, there is no one-size-fits-all solution for every situation.
The book is organized into four sections:
- Introduction and RTOS Concepts
- Toolchain Setup
- RTOS Application Examples
- Advanced RTOS Techniques
Section 1 defines "real-time" and "RTOS", distinguishing between hard, firm, and soft real-time systems. It compares RTOS tasks with bare-metal superloops and parallelism with ISR's and DMA, then covers concurrency concepts like queues, semaphores, and mutexes.
Section 2 covers MCU, development board, toolchain, and debugger selection. That includes how to navigate data sheets and vendor websites, which can be overwhelming when you first start digging into them. Amos explains why he selected the STM32 Nucleo-F767ZI development board, the STM32CubeIDE, and the Segger J-Link, Ozone, and SystemView debug and monitoring tools for the book. This is extremely valuable, because you may find yourself responsible for making such technical decisions some day.
Section 3 goes through several example applications that illustrate setting up and controlling multiple tasks, and managing the interaction between them. Amos uses simple GPIO LED and UART control to make activity visible, but these can be expanded to any resources that need to be shared and coordinated among tasks. He uses the debug tools to monitor and explain the behavior. This is also extremely valuable, because getting information out of a system and interpreting it is a critical part of evaluating and improving it.
Section 4 covers several advanced topics. These include drivers and ISR's, more resource sharing methods (using the USB port as the example peripheral), creating a well-abstracted architecture, loose coupling between tasks, using the CMSIS-RTOS and POSIX API's, memory management, multi-processor and multi-core systems, and troubleshooting tips.
Along the way, Amos discusses various pitfalls, like poor design abstraction, overly tight coupling, priority inversion, and race conditions (go read about the Mars Pathfinder for a fascinating example of priority inversion). These are important topics for building safe products that have a long life over multiple versions and are successful in the marketplace.
All of the examples in the book are fully functional applications, and Amos goes through the steps of setting everything up, building, downloading, running, debugging, monitoring, and evaluating results. Again, this is all extremely valuable, because these are the kind of real-world practical skills you need. Understanding the tools and how to work with them is critical. Even if you use a different tool set, many of the concepts are the same.
For each bit of real code, he goes through a breakdown of the major items in the code, explaining what they do and how to interpret them. He also discusses design considerations and alternatives.
While the applications are simple, they make great starting points for more complex experimentation, because they use the real peripherals on the board and lay out all the necessary scaffolding. That's one thing I really like about this book. A common complaint I've had with other books is that the example code is so trivial that it doesn't really convey much more than you could get from reading the header files. These are much better, providing the kickstart to do real work.
Once you have the practical skills for playing with an application on your Nucleo, you can start reading further in the datasheet and trying out other peripherals. Then you can expand with additional external hardware; the Nucleo has headers for connecting Arduino shields or various other devices. This is where things really get fun and learning really accelerates. Want to connect up sonar sensors? OLED displays? Buttons and controls? Motors? Add a breadboard and component experimentation kit (like this or this) and you can build real functioning product prototypes, then explore your own design alternatives.
This would be an excellent textbook for professional self-study, a college undergraduate or high school course, or an after-school program similar to a robotics club. Combined with:
- an introductory C programming book (Kernighan and Ritchie's The C Programming Language, 2nd edition, being the classic text);
- James Grenning's Test Driven Development for Embedded C;
- a basic Windows laptop (with the free MSYS2 suite installed, for building and running off-target TDD-based unit tests, which yes, you REALLY want to be able to do);
and the Nucleo board, anyone completing all the projects in this book would be armed with an outstanding set of practical skills and background knowledge with real-world applicability.
Previous post by Steve Branam:
Review: Project Management for the Unofficial Project Manager
To post reply to a comment, click on the 'reply' button attached to each comment. To post a new comment (not a reply to a comment) check out the 'Write a Comment' tab at the top of the comments.
Registering will allow you to participate to the forums on ALL the related sites and give you access to all pdf downloads.