This technical blog post compares the performance of async Rust using Embassy against FreeRTOS using C on an STM32F446 microcontroller. Both systems will run applications performing the same actions, judged on interrupt latency, program size, RAM usage, and ease of programming. The applications are designed to provide a basic understanding of how real-time operating systems (RTOS) and async executors function.
The testing will utilize the STM32F446ZET6 microcontroller at 180 MHz, with measurements taken using a Rigol DS1054Z oscilloscope. An async function in Rust returns a future, which is transformed into a state machine object that can be polled. Rust futures are lazy and only execute when polled, with Wakers used to signal when a future should be polled again.
Embassy provides an async interface for many peripherals, allowing for efficient handling of interrupts. In contrast, a real-time operating system divides tasks into independent threads, allowing normal code execution without special programming requirements. This design supports pre-emptive threading, enabling fair execution time and predictable responses to events.
The blog post outlines the implementation of a program in both environments, focusing on three tasks: measuring GPIO interrupt time, thread wait time, and the time between interrupt and thread resumption. The comparison will also consider static memory usage, as dynamic memory usage is challenging to measure.
The author predicts that the RTOS will perform better in certain areas, particularly in context switching and thread management. However, the async model in Rust is expected to be more user-friendly, reflecting trends in web development.
The results of the tests indicate that Embassy/Rust outperformed FreeRTOS/C in several categories, although FreeRTOS showed faster context switching. The author concludes that while FreeRTOS offers more freedom, Embassy/Rust provides a more integrated and user-friendly programming experience.