EmbeddedRelated.com
Blogs
The 2024 Embedded Online Conference

Review: Hands-On RTOS with Microcontrollers

Steve BranamSeptember 20, 20202 comments

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.

This article is available in PDF format for easy printing

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:

  1. Introduction and RTOS Concepts
  2. Toolchain Setup
  3. RTOS Application Examples
  4. 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 and humanity's longest-distance OTA). These are important topics for building safe products that have a long life over multiple versions and are successful in the marketplace.

All 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:

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.

And a tip-o-the-hat to Phillip Johnston, credited as technical reviewer in the book, who's EmbeddedArtistry website is a great resource.



The 2024 Embedded Online Conference
[ - ]
Comment by slimcatarchFebruary 28, 2021

This book is amazing!

[ - ]
Comment by JimYuillOctober 19, 2021

A great book: good material, good example programs, and explained well.

Though, it has a number of bugs and omissions.
A reader (me) created a study-guide for the book, with corrections and added info:
https://jimyuill.com/embedded-systems/study-guide-...

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.

Please login (on the right) if you already have an account on this platform.

Otherwise, please use this form to register (free) an join one of the largest online community for Electrical/Embedded/DSP/FPGA/ML engineers: