Embeddable Libraries

modm: Modular Object-Oriented Development for Microcontrollers

modm (Modular Object-oriented Development for Microcontrollers) is a C++14 framework built by Niklas Hauser and Fabian Greif. The modm project uses vendor-provided chip data with a library builder, enabling modm to automatically generate startup code, chip-specific drivers, external drivers, and BSPs for your platform. Since modm provides a portable HAL, you can easily migrate your software from one processor to another supported processor with no effort.

modm provides a framework which is suitable for bare-metal systems ranging from the ATtiny to a 32-bit ARM Cortex-M. The HAL features no memory allocations, low RAM consumption, and lightweight stack-less threads. The framework also provides useful algorithms suitable for bare-metal systems, as well as drivers for a wide variety of SPI and I2C peripherals. Multitasking is supported through protothreads, a stackless threading implementation targeted for memory constrained systems - each task only requires 2 bytes!

modm is well-tested, featuring 64 test groups with 343 test cases and over 4000 assertions. While the HAL is not fully tested in an automated manner, a variety of example hardware projects are regularly checked by the CI server.

The modm framework currently supports ~1350 AVR and ARM Cortex-M microcontrollers from Atmel, ST, and NXP. If you are using a processor from of those vendors, modm can provide your team with a stable foundation of drivers and the advantage of being able to quickly migrate your software to another processor.

Further Reading

For more on modm:

foonathan/memory: Simplifying the C++ Memory Allocator

The memory library is developed by Jonathan Müller, a C++ library developer and author of foonathan::blog(). This library provides an new STL-compatible C++ memory allocator called RawAllocator. The RawAllocator is similar to the standard Allocator but is easier to use. The library also provides a BlockAllocator type which can be used for allocating large blocks of memory.

The project includes a variety of implementations, adapters, wrappers, and storage classes, including:

  • new allocator
  • heap allocator
  • malloc allocator
  • memory pools
  • static allocator
  • virtual memory allocator
  • make_unique and make_shared replacements which allocate memory using a RawAllocator

We are excited about using this library in our next embedded project and gaining increased control over memory allocations.

Further Reading

For more on the memory library:

CheckedC: A Language Extension to Help Eliminate Memory Errors

Checked C is a research project from Microsoft which adds static and dynamic (runtime) checking for errors such as buffer overruns, out-of-bounds memory accesses, and incorrect type casts.

The project is implemented as an extension to the C language. New pointer and array types are provided with the goal of allowing programmers to better describe intended pointer use and the range of memory that is pointed to. The new Checked C types are:

  • ptr<T>: a pointer without bounds checking, cannot be used in pointer arithmetic, cannot be null when accessing memory
  • array_ptr<T>: a pointer to an element of an array, no bounds checking, can be used in pointer arithmetic, cannot be null when accessing the memory
  • span<T>: a pointer with bounds information, supports pointer arithmetic, cannot be null when accessing memory
  • T array_var checked[s]: an array of type T with size s which is bounds checked

The types provide flexibility - developers can select between types with and without bounds checking, as well as between types that can or cannot be used in pointer arithmetic.

Since Checked C is an extension to the C language, you will need a compiler that supports it. Microsoft provides a port of clang and LLVM that support the extension.

CheckedC can help you identify and eliminate common memory errors which plague us as C & C++ developers. Even better, existing C programs compiled with a Checked C compiler will continue to work. Raw pointers (e.g. int *) remain unchecked and pointer arithmetic is still allowed.

Further Reading

For more on Checked C: