C++20 Coroutines on Microcontrollers - What We Learned
This repo contains projects that investigate the use, on resource-constrained embedded platforms, of the proposed C++ coroutine implementation N4680 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/n4680.pdf).
This code is referenced by our paper "C++20 Coroutines on Microcontrollers - What We Learned". The projects here form part of a larger codebase developed during a wider study into the use of coroutines on microcontrollers in C and C++. This set of projects is a freeze-frame of the larger work-in-progress.
The following software was used for the development environment.
Item | Version | Description |
---|---|---|
Windows | 7 | Operating system |
Kinetis Design Studio | 3.2.0 | Integrated development environment, including build system |
Processor Expert for Kinetis | 3.0.2 | Code generator |
clang | 8.0.0 | C/C++ compiler, including LLVM toolkit |
gcc | 6.3.1 | Linker (arm-none-eabi-g++) |
Item | Version | Description |
---|---|---|
FRDM-K22F | N/A | NXP Semiconductors development board; 120 MHz, 512 kB Flash, 128 kB RAM |
Protothread.h | N/A | Ben Hoyt's C++ port of Adam Dunkels' protothreads library |
MQX Lite | 1.1.1 | Real-time operating system |
FreeRTOS | 10.1.1 | Real-time operating system |
- Clone or copy the repo.
- Open Kinetis Design Studio with clang/llvm on the PATH (see ProjectConfig.md for details).
- (Optional) Create a new workspace.
- Import the 4 projects from this repo into the active workspace.
- Set the Active Build Configuration for each project as shown in the table below.
Project | Configuration |
---|---|
k22ptmin_xt | DebugLLVM_NS |
k22awaitmin_xt | DebugLLVM_NS |
freertos2_xt | DebugLLVM |
mqxmin_xt | DebugLLVM |
k22fawait1 | DebugLLVMc |
k22fawait2 | DebugLLVMc |
k22ffsm2 | DebugLLVMc |
This repo contains many similar projects to compare performance characteristics using different software environments. The projects are listed below.
Project | Summary | Technology |
---|---|---|
k22ptmin_xt | Minimal project to investigate the cost of context switching using Protothreads. Uses an external timer. | Protothreads |
k22awaitmin_xt | Minimal project to investigate the cost of context switching using co_await . Uses an external timer. |
Coroutines |
freertos2_xt | Minimal project to investigate the cost of context switching using FreeRTOS and threads. Uses an external timer. | Threads |
mqxmin_xt | Minimal project to investigate the cost of context switching using MQX Lite and threads. Uses an external timer. | Threads |
k22fawait1 | Simple project to demonstrate microcontroller application development using co_await . |
Coroutines, Lambdas, some STL |
k22fawait2 | Simple project to demonstrate microcontroller application development using co_await (second iteration). |
Coroutines |
k22ffsm2 | Simple project to compare microcontroller application development using finite state machine against co_await . |
FSM |
The repo also contains other resources as follows:
ProjectConfig.md describes the common configuration of the KDS projects that was performed in order to produce the project files listed above. (Each project also contains a readme with project-specific configuration details.)
Library.md briefly describes the design and development of the run-time library.
All the *_xt
projects use the same simple hardware layout. The external wires are connected either to the named pins on the K22F development board or to the probe of the Rohde & Schwarz HMO2024 oscilloscope.
The application projects (k22fawait1, k22fawait2 & k22ffsm2) use the same hardware layout. The external wires are connected either to the named pins on the K22F development board and to the pins of an analog PS2 game joystick (e.g. Thumb Joystick - Sparkfun or PS2 Game Joystick Module For Arduino - Banggood).
Other relevant resources can be found on the ISO C++ site:
Document | Summary |
---|---|
N4775 | Working Draft, C++ Extensions for Coroutines |
P1493 R0 | Coroutines: Use-cases and Trade-offs |
This project is subject to the terms and conditions defined in file 'LICENSE' or 'LICENSE.txt', which is part of this source code package.