Swift.org Apr 3, 2024

Get Started with Embedded Swift on ARM and RISC-V Microcontrollers

Article Summary

Swift just jumped from iOS apps to microcontrollers. The Swift team launched example projects showing how to write firmware for ARM and RISC-V chips using a new experimental compilation mode.

The Swift team released a repository of sample projects demonstrating Embedded Swift, an experimental compilation mode that lets developers write firmware for microcontrollers. The mode disables features like runtime reflection and ABI stability to produce standalone binaries suitable for constrained embedded environments while keeping Swift's familiar syntax.

Key Takeaways

Critical Insight

Swift can now compile to bare metal firmware for popular microcontroller boards while preserving most of the language features developers rely on.

The repository reveals specific integration patterns for bridging vendor SDKs that could change how embedded developers approach firmware architecture.

About This Article

Problem

Swift on microcontrollers had to balance language features with hardware limits. Runtime reflection, ABI stability, and existentials needed to go so the compiler could produce standalone binaries for firmware.

Solution

Apple's compiler team, led by Kuba Mracek, built an experimental Embedded Swift mode that turns off heavy features while keeping Swift's familiar syntax. The approach is documented in the formally accepted Embedded Swift Vision Document.

Impact

The swift-embedded-examples repository now has Embedded Swift working on STM32, Raspberry Pi Pico, Nordic Semiconductor, and ESP32C6 boards. Community members have added support for different build systems and vendor SDKs.

Recent from Swift.org

Related Articles