I would like to announce my small hobby project to create some examples using Swift for Embedded for the STM32C0116-DK.
I based a lot of the code in there off of the swift-embedded-examples but modified them further to make them work well for this particular MCU. These examples are licensed under the MIT, so they can be used by anyone as a starting point for a project that works on STM32C011 MCUs.
So far I only have 3 demos:
blink
: An extremely simple demo that binks LED3 with no external dependencies.blink-mmio
: A very simple demo that blinks LED3, employing swift-mmio and swift-cortex-m libraries.joystick-mmio
: Demo of using the joystick ADC input to blink LED3 at different rates depending on what direction the joystick is depressed.
I do have a plan to update it further in the future to add more demos (like USART and LCD demos), but for now it seems pretty complete to share.
A few things I found in the process of building this, which could be some (maybe) constructive feedback for Swift developers working on embedded:
- Although Swift MMIO is nice to be able to have and use (and the
svd2swift
tool as well), the slow compile times of Swift Macros make it almost painful to use, especially when the project needs to be rebuilt. I timed a release build on my beefy i7 CPU running at 4.7GHz (liquid cooled) and it took almost 5 minutes. This seems excessive, especially when you're generating a binary that is only a few KB in size. I hear that there are efforts in progress to improve the build times of Swift Syntax, but are there other things that can be done to improve this, like precompiling Swift Syntax and MMIO modules ahead of time so they don't need to be rebuilt each time? - I found that Swift Macros and Swift MMIO would get rebuilt each time VSCode resolved package dependencies, so I disabled that using
"swift.disableAutoResolve": true
in .vscode/settings.json to avoid it altogether. Could there be some sort of bug around this that causes the whole project to be rebuilt after resolving dependencies? - I had to create a separate Swift SDK to pass the correct compile flags to Swift for the STM32C011 since they could not be passed directly to
swift build
. I know there is ongoing effort to make it possible to pass specific target flags inswift build
, but it would be nice to have that available for the official Swift for Embedded release so that developers don't have to build a full SDK.
All in all though, it has been fun to learn how to use Swift for Embedded for this project, and it looks very promising for the future.