Apple introduces Swift for ESP32-C6 and other microcontrollers

Swift is a programming language developed by Apple since 2010 that takes up concepts from other languages ​​(such as Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, D …). Since then, Swift has been increasingly used at Apple. Swift for embedded devices and microcontrollers was presented at the WWDC 2024 developer conference.

Advertisement


So far, Swift has been used by Apple for servers, desktops and mobile devices; now it is also set to be used on microcontrollers and smart home devices. In addition to normal applications, it is also intended to be suitable for kernel code and libraries, which were previously the domain of C and C++. The security features and memory management are intended to help avoid errors. If you want to know more, you can take a look at Apple’s vision for Swift.

Embedded Swift supports most of Swift’s language constructs on larger architectures. So far, Embedded Swift supports the ESP32-C6, Raspberry Pi RP2040, STM32F7 and nRF52840 microcontrollers. Examples of the platforms already exist on GitHub. The most extensive support is for the RISC-V microcontroller Espressif ESP32-C6. In contrast to Python or Basic on microcontrollers, Swift must be compiled, which requires a development system based on C/C++ and the development kit from the hardware manufacturer. Video on Apple’s website The Espressif SDK is used with the Espressif SP32-C6 DevKitC-1 development board.

The second example then also uses the LED on the board to control it through Swift, the classic “Helloworld” on microcontrollers. For this, a so-called bridging header (BridgingHeader.h) is used, which makes the SDK C APIs available in Swift. This then allows you to access the board’s features directly via the hardware and make the LED flash. Of course, this is not really elegant and also error-prone, so you can abstract the hardware in another layer (or library). Unfortunately, with a new programming language, you don’t have any ready-made libraries and have to write a lot yourself or hope that other developers do it. You can then do this for a Matter C++ API, as demonstrated in the video, and thus develop an IoT device (in the video, a “smart” IoT LED lamp).



Apple Swift Code in Neovim

(Picture: Apple Inc.)

This means that the only target group for embedded Swift is probably the die-hard Apple programmer who wants (or needs) to program devices suitable for the Apple universe. Makers and casual programmers will stick with C/C++, Arduino, MicroPython or even Basic. The latter two languages ​​are even interpreted and if speed is not the most important thing, they can be used to quickly get programs onto the board.




The ESP32-CAM is popular with makers – compact, but equipped with a powerful ESP32 microcontroller, a video-capable camera module and a MicroSD card slot. If you want to get the most out of the board, it’s worth taking a deeper look at the hardware internals and programming interfaces. The 80-page Make special takes readers by the hand and thanks to the included ESP32-CAM board including 2 MP camera module and programming adapter, you can get started with your first projects straight away.


(caw)

To home page

source site