EmbeddedRelated.com

Simple C++ State Machine Engine

Massimiliano Pagani March 14, 2024

When implementing state machines in your project it is an advantage to rely on a tried and tested state machine engine. This component is reused for every kind of application and helps the developer focus on the domain part of the software. In this article, the design process that turns a custom C++ code into a finite-state machine engine is fully described with motivations and tradeoffs for each iteration.


Creating a GPIO HAL and Driver in C

Jacob Beningo February 28, 2024

Creating a GPIO Hardware Abstraction Layer (HAL) in C allows for flexible microcontroller interfacing, overcoming the challenge of variability across silicon vendors. This method involves reviewing datasheets, identifying features, designing interfaces, and iterative development, as detailed in the "Reusable Firmware" process. A simplified approach prioritizes essential functions like initialization and read/write operations, showcased through a minimal interface example. The post also highlights the use of AI to expedite HAL generation. A detailed GPIO HAL version is provided, featuring extended capabilities and facilitating driver connection through direct assignments or wrappers. The significance of a configuration table for adaptable peripheral setup is emphasized. Ultimately, the blog illustrates the ease and scalability of developing a GPIO HAL and driver in C, promoting hardware-independent and extensible code for various interfaces, such as SPI, I2C, PWM, and timers, underscoring the abstraction benefits.


Getting Started With Zephyr: Bluetooth Low Energy

Mohammed Billoo January 29, 2024

In this blog post, I show how to enable BLE support in a Zephyr application. First, I show the necessary configuration options in Kconfig. Then, I show how to use the Zephyr functions and macros to create a custom service and characteristic for a contrived application.


++i and i++ : what’s the difference?

Colin Walls January 25, 20242 comments

Although the ++ and -- operators are well known, there are facets of their operation and implementation that are less familiar to many developers.


Lightweight C++ Error-Codes Handling

Massimiliano Pagani November 16, 20232 comments

The traditional C++ approach to error handling tends to distinguish the happy path from the unhappy path. This makes handling errors hard (or at least boring) to write and hard to read. In this post, I present a technique based on chaining operations that merges the happy and the unhappy paths. Thanks to C++ template and inlining the proposed technique is lightweight and can be used proficiently for embedded software.


Creating a Hardware Abstraction Layer (HAL) in C

Jacob Beningo October 23, 20233 comments

In my last post, C to C++: Using Abstract Interfaces to Create Hardware Abstraction Layers (HAL), I discussed how vital hardware abstraction layers are and how to use a C++ abstract interface to create them. You may be thinking, that’s great for C++, but I work in C! How do I create a HAL that can easily swap in and out different drivers? In today’s post, I will walk through exactly how to do that while using the I2C bus as an example.


Handling Translations in an Embedded Project

Mattia Maldini October 13, 20234 comments

A brief walkthrough on how to handle human language translations in a low level C application. Some options are listed, each with advantages and disadvantages laid out.


There are 10 kinds of people in the world

Colin Walls September 27, 2023

It is useful, in embedded software, to be able to specify values in binary. The C language lacks this facility. In this blog we look at how to fix that.


Embedded Developers, Ditch Your IDEs – Here’s Why!

Amar Mahmutbegovic September 25, 20231 comment

Ditching your Integrated Development Environment (IDE) temporarily can be a transformative learning experience in embedded development. This post invites you to explore the underpinnings of IDEs by delving into alternative tools and processes like Makefile, CMake, Vim, GDB, and OpenOCD. Understanding these tools can demystify the background operations of IDEs, revealing the intricacies of compiling, linking, and debugging. This journey into the “under the hood” aspects of development is not just about learning new tools, but also about gaining a deeper appreciation for the convenience and efficiency that IDEs provide. By stepping out of your comfort zone and experimenting with these alternatives, you can sharpen your skills, enhance your knowledge, and possibly discover a more tailored and streamlined development experience. Whether you're a novice or a seasoned developer, this exploration promises insights and revelations that can elevate your embedded development journey.


New book on Elliptic Curve Cryptography

Mike August 30, 20234 comments

New book on Elliptic Curve Cryptography now online. Deep discount for early purchase. Will really appreciate comments on how to improve the book because physical printing won't happen for a few more months. Check it out here: http://mng.bz/D9NA


Visual Studio Code Extensions for Embedded Software Development

Jacob Beningo March 22, 20238 comments

Visual Studio Code has become one of the most popular IDEs in the world. To date, software developers have downloaded it more than 40 million times! I suspect you’ve at least heard of it, if not already attempting to use it. Visual Studio Code allows developers to easily customize their development environment which can help them accelerate development, minimize bugs, and make developing software overall much better.

One challenge with Visual Studio Code is that embedded software...


C to C++: Bridging the Gap from C Structures to Classes

Jacob Beningo May 23, 20238 comments

In our last post, C to C++: Proven Techniques for Embedded Systems Transformation, we started to discuss the different ways that C++ can be used to write embedded software. You saw that there is no reason to be overwhelmed by trying to adopt complex topics like metaprogramming out of the gate. An important concept to understand is that you can make the transition gradually into C++ while still receiving the many benefits that C++ has to offer.

One of the first concepts that a C...


Modern C++ in Embedded Development: (Don't Fear) The ++

Amar Mahmutbegovic June 13, 20232 comments

While C is still the language of choice for embedded development, the adoption of C++ has grown steadily. Yet, reservations about dynamic memory allocation and fears of unnecessary code bloat have kept many in the C camp. This discourse aims to explore the intricacies of employing C++ in embedded systems, negotiating the issues of dynamic memory allocation, and exploiting the benefits of C++ offerings like std::array and constexpr. Moreover, it ventures into the details of the zero-overhead principle and the nuanced distinctions between C and C++. The takeaway? Armed with the right knowledge and a careful approach, C++ can indeed serve as a powerful, safer, and more efficient tool for embedded development.


Cracking the (embedded) Coding Interview

Manasi Rajan March 23, 2023

You never forget the day you land your first job. 

The thrill of receiving that call from your recruiter to tell you that you bagged your dream role! The relief when you finally see the offer letter you’ve been working towards for years. The pride in your parents' voices when you call home and say “Hey look Ma, I’ve made it!”

But before that, there’s the grueling screening process to get through. Tech interviews often last up to three months and companies can have five...


Scorchers, Part 3: Bare-Metal Concurrency With Double-Buffering and the Revolving Fireplace

Jason Sachs July 25, 20201 comment

This is a short article about one technique for communicating between asynchronous processes on bare-metal embedded systems.

Q: Why did the multithreaded chicken cross the road?

A: to To other side. get the

— Jason Whittington

There are many reasons why concurrency is


C to C++: 3 Reasons to Migrate

Jacob Beningo October 31, 202222 comments

I’ve recently written several blogs that have set the stage with a simple premise: The C programming language no longer provides embedded software developers the tools they need to develop embedded software throughout the full software stack. Now, don’t get me wrong, C is a powerhouse, with over 80% of developers still using it; however, as embedded systems have reached unprecedented levels of complexity, C might not be the right tool for the job.

In this post, I’m kicking off a series...


Review: Hands-On RTOS with Microcontrollers

Steve Branam September 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


C to C++: 5 Tips for Refactoring C Code into C++

Jacob Beningo July 23, 20235 comments

The article titled "Simple Tips to Refactor C Code into C++: Improve Embedded Development" provides essential guidance for embedded developers transitioning from C to C++. The series covers fundamental details necessary for a seamless transition and emphasizes utilizing C++ as a better C rather than diving into complex language features. The article introduces five practical tips for refactoring C code into C++. Replace #define with constexpr and const: Discouraging the use of #define macros, the article advocates for safer alternatives like constexpr and const to improve type safety, debugging, namespaces, and compile-time computation. Use Namespaces: Demonstrating the benefits of organizing code into separate logical groupings through namespaces, the article explains how namespaces help avoid naming conflicts and improve code readability. Replace C-style Pointers with Smart Pointers and References: Emphasizing the significance of avoiding raw pointers, the article suggests replacing them with C++ smart pointers (unique_ptr, shared_ptr, weak_ptr) and using references


Creating a Hardware Abstraction Layer (HAL) in C

Jacob Beningo October 23, 20233 comments

In my last post, C to C++: Using Abstract Interfaces to Create Hardware Abstraction Layers (HAL), I discussed how vital hardware abstraction layers are and how to use a C++ abstract interface to create them. You may be thinking, that’s great for C++, but I work in C! How do I create a HAL that can easily swap in and out different drivers? In today’s post, I will walk through exactly how to do that while using the I2C bus as an example.


C to C++: 3 Proven Techniques for Embedded Systems Transformation

Jacob Beningo February 7, 20234 comments

For 50 years, the C programming language has dominated the embedded software industry. Even today, more than 80% of embedded projects are using C; however, over the last few years, many teams have begun transitioning from C to C++. C++ offers embedded developers a robust, modern set of tools that can be used to write flexible, scalable, and reusable applications. As embedded applications become more complex and connected, teams need a more modern language to help them deal with the software...