Apple has released a beta version of Embedded Swift that notably works with Espressif ESP32-C6 wireless RISC-V microcontroller, and the company also built a Matter sample based on ESP-IDF and ESP-Matter SDKs. Embedded Swift is not limited to the ESP32-C6 and supports other microcontrollers from STMicro, Raspberry Pi, Nordic Semi, etc…
Apple Swift programming language is mostly designed for mobile app development, but we’ve also seen it being used on Mad Machine’s SwiftIO board powered by a 600 MHz NXP i.MX RT1052 Arm Cortex-M7 crossover processor and the tiny SwiftIO Micro launched a few years later. The company has now decided to create a subset of the Swift programming language better suited to microcontrollers simply called Embedded Swift that’s currently working on STMicro STM32F746, Raspberry Pi Pico, nRF52840, and ESP32-C6.
The “Go small with Embedded Swift” presentation at WWDC 2024 shows how to get started with Embedded Swift using Espressif Systems’ESP32-C6-DevKitC-1 development board running simple demos such as “Hello world” and changing color on a RGB LED up to a more complex demo using the Matter protocol for the Smart Home.
This is what the code for the RGB LED looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
let led = LED() @_cdecl("app_main") func app_main() { print("🏎️ Hello, Embedded Swift!") led.color = .red led.brightness = 80 while true { sleep(1) led.enabled = !led.enabled if led.enabled { led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100) } } } |
It looks quite similar to C without the semi-colons… You’ll find the sample code for the Matter demo on GitHub, and additional Embedded Swift examples for ESP32-C6, STM32, RP2040, and nRF52840 in a separate repository.
Apple explains that Embedded Swift is a subset of the Swift programming language with a much smaller footprint (the binary can be around 10KB based on the diagram below). They’ve removed some features but added others needed for MCU-class hardware such as the ability to access memory-mapped registers through the Swift MMIO library. Support is provided through online forums.
I assume most developers already familiar with the ESP-IDF will ignore this news, but Swift mobile application developers may have a shorter learning curve with Embedded Swift than having to learn to use the ESP-IDF framework or Arduino programming. Note that Embedded Swift is still at the development stage, so you need to download snapshots of Swift to try it out since there’s no stable release just yet.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
I hope no any smart aleck will think of using this in production. Let DIY enthusiasts and smoothie lovers blink an LED from their toy laptop; that should be enough for them.
I only have a passing familiarity with Swift (literally can’t write an hello world) but it’s a compiled language without a garbage collector that error handles without an exceptions stack so it should be more suitable for micros than c++ while offering some conveniences over C.
I think it will come down to how much cheaper Swift devs are going to be compared to Rust and experienced C devs. After all, compared to embedded c and rust people, mobile devs aren’t exactly in short supply.
Okay so another entire tech stack to please Apple enthusiasts… Who don’t know python?
Let you divide the industry again, Apple? Sigh.
Well this all comes down to library support, like any other… So goodluck reinventing the wheel just so you can use some language features.
I’m Ines from MadMachine. I think Embedded Swift has tons of potential for more complex applications like UI apps. While simple tasks like blinking an LED and reading sensor values can be handled by common MCUs, as MCUs get more powerful and tasks get more complex, languages like Swift and Rust become better choices.
Our team has been working on bringing Swift to embedded development since 2019, and we have been struggling with library support since then, lol. But now, we’ve got a pretty solid framework that lets us focus on developing cool applications for hardware.
It is very useful technology and these very good 👍 and smooth work on devices
So I mostalally use