Embedded Template Library

Updated: 20181219

We've been hard at work on our C++ embedded systems framework. A critical design requirement is that the framework core components do not utilize dynamic memory allocation. Unfortunately, this excludes most of the STL containers, as they get storage from the heap by default. Rather than reinventing the wheel, we spent some time searching for existing solutions to this problem. We were quite lucky to discover the Embedded Template Library, an open-source project created by John Wellbelove at Aster Consulting Ltd.

The Embedded Template Library (ETL) is complementary to the Standard Template Library (STL). The ETL provides fixed-size alternatives to STL container type. The ETL containers specify a maximum capacity at compile-time and make no calls to malloc/free/new/delete. As an added bonus, the containers are all cache friendly: storage for all container types is allocated in contiguous blocks.

Most of the ETL containers mimic, as best as possible, the existing STL containers. Additional container types are also provided, such as for memory pools.

We have been heavily using the following ETL modules while developing our framework:

The ETL goes further than just providing fixed-size STL container alternatives. The entire library does not use dynamic memory allocation. All storage is allocated either at compile time or on the stack. The library also uses no run-time type information (RTTI). The library provides configurable error handling by allowing the user to choose exceptions, assertions, error logging, or to completely disable error checking.

The library also provides a variety of additional algorithms, utilities, and other features that are useful to embedded systems developers, including:

The ETL is designed to work with C++03, since many projects and chipsets cannot support the newer standards. The ETL is an excellent way to gain access to some modern C++ features on C++03 projects.

The project is well-documented, with reference information available on the ETL Website. John also provides free email support for the ETL.

The ETL is released under the MIT License.

Further Reading

Change Log

  • 20181219:
    • Fixed links for ETL modules

Related Articles

EMB2: A C/C++ Framework for Multi-core and Multi-chip Embedded Systems

EMB2 is a C/C++ framework developed by Siemens and the University of Houston. EMB2 provides generic building blocks for building multi-core or multi-chip embedded applications, including basic parallel algorithms, concurrent data structures, and application skeletons. Since EMB2 is targeted for embedded applications, it provides soft-real-time support, predictable memory consumption (no dynamic memory allocations after startup), support for task priorities and affinities, and non-blocking APIs.

The framework utilizes the Multicore Association's Task Management abstraction layer, MTAPI, enabling EMB2 programs to be easily ported to new operating systems and processor architectures. By utilizing MTAPI, heterogeneous and distributed embedded programming is simplified, and developers can easily distribute work across processor cores, hardware accelerators, GPUs, DSPs, FPGAs, or networked devices.

The EMB2 base library is implemented as a C API with C++ wrappers, while the parallel algorithms, dataflow patterns, and concurrent containers are implemented in C++. C99 and C++03 are used as the implementation standard to provide maximum usability in the embedded world, though C11 and C++11 are also supported.

If you are building a product which uses a multi-core processor, multiple processors, or hardware accelerators, EMB2 provides a solid and portable foundation that will enable your team to take full advantage of your system's hardware resources.

For more on EMB2:

crect: A C++14 Library for Generating a Stack Resource Policy Scheduler at Compile Time

The crect project (pronounced correct) is a C++14 library for generating a scheduler for Cortex-M microcontrollers at compile-time. crect uses the Cortex-M's Nested Vector Interrupt Controller (NVIC) to implement a Stack Resource Policy (SRP) scheduler which guarantees deadlock-free and data-race-free execution.

crect is built upon the Kvasir Meta-programming Library, which is also the foundation of the Kvasir framework. Use of C++ meta-programming and C++14 features allows priority ceilings and interrupt masks to be calculated at compile time. Resource locks are handled through RAII, and resource access is handled using a monitor pattern).

The most impressive thing about this framework is the minimal resource requirements:

  • ~400 bytes of memory for the static elements (linked list, SysTick, time implementation)
  • 4-5 instructions per job for initializing the NVIC
  • 2-3 instructions per queue element for initializing the asynchronous queue
  • 3-4 instructions + 4 bytes of stack space for a lock
  • 1-3 instructions for an unlock
  • 2-4 instructions for a pend/clear
  • 20-30 instructions per item in the queue for async

If you are working on a bare-metal ARM program with real-time concerns, crect is an RTOS alternative that can provides protection against common multithreading concerns like priority inversion, deadlocks, and race conditions.

Further Reading

For more on crect:

Related Posts