How to Troubleshoot Embedded Swift and the Matter Smart Light

Опубликовано: 05 Апрель 2025
на канале: Paul Solt
524
12

In this video I'll share some additional tips from getting the Embedded Swift project to build and contorl the Matter Smart Light using an ESP32-c6 micro controller.

Read the article: https://blog.supereasyapps.com/how-to...

I'm new to embedded programming, so this is all a big experiment. Please let me know if this helps you:

00:00 Getting Started with Embedded Swift
00:30 Home Kit LED Control using Swift
02:15 How to Get Started
06:30 Testing Swift Toolchains
10:50 Set up IDF Shell
13:20 Smart Light Starter Project
18:50 Install Firmware and Run
19:38 Fix the LED GPIO
22:50 Success - LED is ON
24:24 Troubleshoot HomeKit Accessory
25:48 Add HomeKit Accessory

Add to your ~/.zshrc file

Add this line to your zsh configuration file (create + open it if you don't have one):

export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw /Library/Developer/Toolchains/swift-latest.xctoolchain/Info.plist)

Reload the configuration file:

source ~/.zshrc

Test the toolchain using your tool:

echo $TOOLCHAIN
swift --version

You should see output that looks like this, using your own toolchain identifier:


swift --version

Apple Swift version 6.0-dev (LLVM 0ad8ad0245d47b4, Swift 01bd2b4f8c84d45)
Target: arm64-apple-macosx14.0

That should match the output if you override the variable before the command in this format:

TOOLCHAINS=org.swift.59202407151a swift --version

Apple Swift version 6.0-dev (LLVM 0ad8ad0245d47b4, Swift 01bd2b4f8c84d45)
Target: arm64-apple-macosx14.0

If you dont' see the correct version, you may not have the toolchain setup properly. Redo those steps before proceeding, or you will not be able to build the code. You'll need to clean the project to remove the wrong build artifacts.

Embedded Swift is only available in the current trunk of the main Swift branch, so you need to make sure you're not using the Swift 6 toolchain or the Swift 5 toolchain using those environmental variables.

At this point you can setup the environment:

Setup the ESP-IDF environment

. ~/esp/esp-idf/export.sh

Setup the ESP-Matter environment

. ~/esp/esp-matter/export.sh

If you change Swift toolchains, make sure to clean the idf environment

idf.py clean

If that doesn't work, try deleting the build folder.

rm -rf build

Then try the build process again with idf.

idf.py set-target esp32c6

idf.py build

idf.py flash monitor

Exit monitor: `Control + ]`

Reset the Matter Accessory and Try Again

You can reset your device using this command.

idf.py erase-flash

Then retry and build and run (all-in-one)

idf.py build flash monitor

Customize your LED GPIO Pin

Apple's code makes assumptions about the GPIO value for the LED. Different boards will require different values. Read your boards documentation to figure out what number to use if your board is different.

In the LED.swift, I customize the config to set the GPIO value of the LED:

```swift
init() {
var config = led_driver_get_config()
print("config.gpio: \(config.gpio)")
config.gpio = 23 // default is 8

let handle = led_driver_init(&config)
led_driver_set_power(handle, true)
self.handle = handle!
}
```


Links

Swift Matter Examples: https://apple.github.io/swift-matter-...
macOS Setup: https://apple.github.io/swift-matter-...
Smart Light: https://apple.github.io/swift-matter-...
Swift Toolchains: https://www.swift.org/download/
Cannot connect Issue: https://github.com/apple/swift-matter...


Install CVCP Drivers for macOS

These drivers will allow you to see the serial port connection in macOS for the uart/USB device. Without them you will only see the `tty` interface and not the `cu.*` interface.

https://www.silabs.com/developers/usb...

CP210x VCP Mac OSX Driver

https://www.silabs.com/documents/publ...

(Unblock pop-ups in Safari)

Unblock Driver

Privacy & Security

1. Silicon Laboratories Inc (Background Mode) below Login Items: "Allow in Background"
2. System software from the following developers was updated and the system needs to be restarted before it can be used.
3. CP210xVCPDriver (Enable it)


#embeddedswift #swift #esp32 #esp32-c6 #embeddedprogramming #programming #coding #hardware #firmware #idf #LED #blink