Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It is important to note that C++20 coroutines were designed primarily for use on desktop and server environments, and not optimized for embedded systems such as AVR. That being said, it is possible to use coroutines on AVR with some limitations and additional requirements.

  1. Compiler support: Coroutines require a compiler that supports C++20 features such as std::coroutine and co_await. Currently, none of the major compilers for AVR (avr-gcc, avr-clang) support these features, so a custom implementation or port may be necessary.

  2. Stack size: Coroutines require a larger stack than regular functions, as they maintain additional state information. AVR devices typically have limited RAM, so ensuring adequate stack space is important.

  3. Context switches: Coroutines rely heavily on context switching, which can be expensive in terms of execution time and memory usage on AVR. Additional optimizations may be required to reduce the cost of context switches.

  4. Use case: It is important to consider whether using coroutines on AVR is the best solution for a given use case. The added complexity and overhead of coroutines may not be necessary for simple applications.

In summary, using C++20 coroutines on AVR requires careful consideration and possible custom implementation. It may not be the most efficient or practical solution in many cases.