Prefer gcc-ar to ar In Your Buildsystems

While working on our Creating a Cross-Platform Build System for Embedded Projects using Meson course, I fell into a rabbit hole while writing the lesson on link-time optimization (LTO). I enabled LTO support using Meson's built-in option: meson buildresults -Db_lto=true Everything worked just fine with the native toolchain setup. Next, I tested LTO support with …

Arduino Library-to-Library Dependencies

I'm building a series of Arduino libraries that are meant to work together. I was quite surprised to learn that there's no straightforward and well-documented way to indicate that one Arduino library depends on another! Instead, users currently need to manually manage dependencies by installing the proper libraries. Planned Dependency Support It seems that Arduino …

Improve volatile Usage with volatile_load() and volatile_store()

A C++ proposal for deprecating the volatile keyword has surfaced. This may surprise our readers, because as Michael Caisse said, "volatile is the embedded keyword." The original intent of the volatile keyword in C89 is to suppress read/write optimizations: No cacheing through this lvalue: each operation in the abstract semantics must be performed (that is, …

Simple Fixed-Point Conversion in C

Operating on fixed-point numbers is a common embedded systems task. Our microcontrollers may not have floating-point support, our sensors may provide data in fixed-point formats, or we may want to use fixed-point mathematics control a value's range and precision. There numerous fixed-point mathematics libraries around the internet, such as fixed_point or the Compositional Numeric Library …

LINEAR11 Conversion Using a Sign Extension Bit Twiddling Hack

The LINEAR11 data format is used by PMBus (Power Management Bus) devices. LINEAR11 is a 16-bit number which is composed of a pair of two’s complement signed integers. When I was faced with converting from LINEAR11 to floating-point, I ended up running into sign extension problems. Luckily, I stumbled upon a simple trick that we can use …

FreeRTOS Task Notifications: A Lightweight Method for Waking Threads

I was recently implementing a FreeRTOS-based system and needed a simple way to wake my thread from an ISR. I was poking around the FreeRTOS API manual looking at semaphores when I discovered a new feature: task notifications. FreeRTOS claims that waking up a task using the new notification system is ~45% faster and uses …

nothrow new: the Variant to Use When Avoiding C++ Exceptions

I'm a relatively young C++ developer, having spent the majority of my career programming in C. While I've devoted myself to the study of the language, I still frequently learn about new features and capabilities that surprise me. I recently learned about nothrow new, a version of the new operator which returns a nullptr on …