# Embassy — Async Embedded Framework for Rust Microcontrollers > A modern embedded framework for Rust that brings async/await to microcontrollers, enabling concurrent firmware without a traditional RTOS. ## Install Save as a script file and run: # Embassy — Async Embedded Framework for Rust Microcontrollers ## Quick Use ```bash # Install prerequisites rustup target add thumbv7em-none-eabihf cargo install probe-rs-tools # Create a new Embassy project for nRF52840 cargo init --name my-firmware # Add embassy dependencies in Cargo.toml, then: cargo run --release # flashes and runs via probe-rs ``` ## Introduction Embassy is an embedded framework for Rust that brings async/await programming to microcontrollers. Instead of a traditional RTOS with threads and context switches, Embassy uses Rust's async executor to run concurrent tasks cooperatively, resulting in smaller binaries and lower RAM usage while maintaining a familiar programming model. ## What Embassy Does - Provides an async executor optimized for embedded systems with zero-alloc operation - Offers HAL (Hardware Abstraction Layer) crates for STM32, nRF, RP2040, and ESP32 - Includes async drivers for UART, SPI, I2C, USB, Bluetooth, and Wi-Fi - Supplies timing utilities with hardware timer integration for delays and timeouts - Enables concurrent firmware tasks without manual state machines or RTOS threads ## Architecture Overview Embassy consists of an executor that polls async tasks using hardware interrupts as wakers, plus HAL crates wrapping chip peripherals as async-capable drivers. The executor uses no heap allocation — all tasks are statically allocated at compile time. When no task is ready, the executor puts the CPU to sleep until a hardware interrupt fires. This provides concurrency with minimal power consumption and predictable memory usage. ## Self-Hosting & Configuration - Requires Rust nightly for async trait support in embedded contexts - Target chip selected via Cargo features (e.g., embassy-stm32 with chip feature) - probe-rs tool handles flashing and RTT-based logging - Memory layout defined via memory.x linker script per target board - Cargo.toml features control which peripherals and protocols are compiled in ## Key Features - True async/await on bare metal with no heap allocation required - Automatic low-power sleep when all tasks are idle - Type-safe peripheral access preventing pin conflicts at compile time - Built-in async networking stack (embassy-net) with TCP, UDP, DHCP, and DNS - Integrated defmt logging framework for efficient binary-format debug output ## Comparison with Similar Tools - **RTIC** — Interrupt-driven concurrency; Embassy uses async tasks which are more composable - **FreeRTOS (Rust bindings)** — C-based with Rust wrappers; Embassy is pure Rust with ownership guarantees - **Zephyr** — Full RTOS in C; Embassy leverages Rust type system for compile-time safety - **TinyGo** — Go for embedded; Embassy provides zero-cost abstractions without GC - **bare-metal Rust (no framework)** — Manual interrupt handling; Embassy adds structured concurrency ## FAQ **Q: Does Embassy replace an RTOS?** A: For many use cases, yes. Async tasks provide concurrency without context switching overhead. For hard real-time with strict priority preemption, consider RTIC alongside Embassy. **Q: Which chips are supported?** A: STM32 (most families), nRF52/nRF53/nRF91, RP2040/RP2350, and ESP32 series via esp-hal integration. **Q: Does Embassy support networking?** A: Yes. embassy-net provides async TCP/UDP sockets. Wi-Fi and Ethernet drivers are available for supported chips. **Q: How does power consumption compare to an RTOS?** A: Embassy automatically enters low-power sleep when idle, often achieving lower consumption than polling-based RTOS patterns. ## Sources - https://github.com/embassy-rs/embassy - https://embassy.dev/book/ --- Source: https://tokrepo.com/en/workflows/asset-22801cfc Author: Script Depot