This content originally appeared on Level Up Coding - Medium and was authored by Alberto Tontoni
Recommendation of four awesome libraries.
As a passionate embedded systems developer, I’ve faced a non-neglectable amount of situations in which I had to somehow reinvent the wheel.
In those cases, I simply tell myself that no such library’s available for the platform I’m using or, if there’s something useful out there, it is unfortunately cluttered with a lot of Arduino delay() function calls… even though it is a library for binary tree handling.
But I admit there are unicorns out there: cross-platform, well-documented, (almost) bug-free libraries that have no dependency on architecture-specific code, and therefore can be put inside your embedded project as they are!
Today I will share with you 4 among the best C/C++ libraries that are very, very likely compatible with the microcontroller you’re working with!
Alright, let’s move on.
1. Unity
Have you ever experienced Test-Driven Development (TDD) on an Arduino?
If so, I’m sure you’ve already made use of the Unity test library.
Although other alternatives for TDD do exist (eg. CppUtest), one of its main advantages comes from the fact that Unity is a plain old C library: with a bit of luck, it will easily integrate inside your project.
But how does it work? First of all, you define your own functions to access the standard output: these will be used to print the result of the tests.
Then, you write a bunch of unit tests, which are nothing but void functions, and use a utility method to add them to the Unity test list. As an example, take a look at this code:
When I flash and run the program on a microcontroller, It prints out this kind of message:
2. CMSIS
Okay, this may be the most widespread piece of code for ARM-based microcontrollers, that some of us have leveraged for a great amount of time without even knowing about its existence.
Common Microcontroller System Interface Standard (CMSIS) is a set of interfaces defined by ARM whose aim is to improve interoperability between microcontrollers made by different vendors.
Using CMSIS, you have access to standardized RTOS, HAL, and even Neural Networks packages that are fully portable between completely different devices.
For you interest, there are also header-only, vendor-specific packages that simplify “bare metal” C programming (take a look at Device).
I guess it’s worth to specify that, however, ARM doesn’t take care of the implementation process. Therefore it’s very common, for example, to be provided with an implementation of RTOS but not with the one for HAL.
In other words, you have to take a look whether some guy has implemented the module you’re looking for. To cite one of my favorite movies:
It is a hero, not the hero we deserved but the hero we needed.
3. FreeRTOS
FreeRTOS is an open source Real-Time Operating System that has been ported to a great number of microcontrollers. It offers a variety of utilities for concurrent programming and access to shared resources, such as tasks, queues, mutexes, and non-blocking delays!
One of its killer features is, however, its huge community: whatever will be your problem, it’s very likely you will find a well-enstablished solution by typing a bunch of words inside your Google search bar.
So, if you are willing to embrace the power of an embedded OS without having to bind to any closed, proprietary solution, consider giving FreeRTOS a try.
4. Embedded Template Library
As a C++ hobbyist, I’ve always dreamed of a way to get rid of plain old C arrays within my embedded code…
You know, maybe using something like the STL!
Well, I’m proud to announce that the solution has finally come.
Made by John Wellbelove, the Embedded Template Library (ETL) is a compromise between ease of use and efficiency, while keeping your code as deterministic as it has always been. In fact, every ETL container has fixed capacity determined at compile time: no malloc/free at all!
The package also includes some reference implementations for standard design patterns, such as the GoF Visitor, and Observer.
It definitely deserves a star on GitHub!
Thanks for reading up to this point. If you have any additional recommendation about fancy C/C++ libraries suitable for embedded systems, please post them in the comment section!
My Favorite Libraries for Embedded Systems was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Alberto Tontoni
Alberto Tontoni | Sciencx (2022-04-17T16:56:25+00:00) My Favorite Libraries for Embedded Systems. Retrieved from https://www.scien.cx/2022/04/17/my-favorite-libraries-for-embedded-systems/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.