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, …
Continue reading "Improve volatile Usage with volatile_load() and volatile_store()"
Using Custom Build Steps with Eclipse Auto-generated Makefiles
Today we have a guest post by Paul Shepherd. Paul describes the process he uses to define custom build steps when using Eclipse auto-generated Makefiles. He uses build version tagging to demonstrate this process.
Continue readingUsing Custom Build Steps with Eclipse Auto-generated Makefiles
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 …
Continue reading "LINEAR11 Conversion Using a Sign Extension Bit Twiddling Hack"
Simulating Open-Drain GPIO in Software
In today's day and age, it's rare to find a modern microcontroller that does not support configurable GPIO. We can easily take these configuration options for granted, especially when interacting with circuits and communication busses (e.g. I2C) that require GPIO to be configured in open-drain mode. As embedded developers we do not always get to …
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 …
Continue reading "FreeRTOS Task Notifications: A Lightweight Method for Waking Threads"
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 …
Continue reading "nothrow new: the Variant to Use When Avoiding C++ Exceptions"
A Warning When Using -fno-exceptions
As an embedded C++ developer, I typically write programs with exceptions disabled. My typical method for accomplishing this is by using the -fno-exceptions compiler flag. Unfortunately, I never realized a very important detail: even if I compile with -fno-exceptions, the C++ libraries I'm using have not been compiled with -fno-exceptions. In order to be truly …
