Hasty Briefsbeta

Bilingual

Running Bare-Metal Rust Alongside ESP-IDF on the ESP32-S3's Second Core

3 days ago
  • #Bare-Metal Rust
  • #ESP32-S3
  • #FreeRTOS
  • The ESP32-S3's dual-core architecture allows running bare-metal Rust on Core 1 alongside ESP-IDF and FreeRTOS on Core 0, enabling a hybrid environment that leverages Rust's safety for time-critical tasks while using C-based ESP-IDF for Wi-Fi and BLE.
  • By setting CONFIG_FREERTOS_UNICORE=y, FreeRTOS is disabled on Core 1, allowing Rust code to run without scheduler preemption, which is essential for high-performance applications like audio processing with minimal jitter.
  • Shared memory and atomic operations (e.g., AtomicU32) facilitate communication between cores, with Rust code incrementing a counter that Core 0 reads, demonstrating cross-core data exchange without mutexes or complex synchronization.
  • Two approaches are presented: static linking (Rust as a library compiled into the firmware) and runtime loading (Rust as a standalone binary in a flash partition), offering flexibility for development and deployment, including hot-swappable updates.
  • Key implementation steps include reserving RAM for Core 1 with SOC_RESERVE_MEMORY_REGION, using an assembly trampoline to set up the stack pointer, mapping flash partitions via MMU, and handling .data/.bss initialization in Rust for standalone binaries.