This sample code is demonstrating a "full" graphical firmware running on an STM32 microcontroller board, concretely the STM32F746G "Discovery" board. It shows using:
- ELF file format, linking with lld, with a custom simple linker script (and thus it builds identically on both macOS and Linux hosts)
- LLVM Embedded Toolchain for ARM
- LVGL graphical/input/animation library
- The DRAM, LCD, touch panel, GPIO pins and interrupts on the STM32F746G
- No other SDKs or library dependencies -- all the startup code, including MCU, board and peripheral initialization is done in Swift source code
Additionally, this sample code:
- Has LSP integration set up via the
.sourcekit-lsp/config.json
file, confirmed to work in multiple code editors (VS Code, Sublime Text, Zed) - Uses SwiftPM's toolset.json to define compiler and linker flags
- Has a host OS (macOS, Linux) "simulator" using SDL that can use the same "business logic" code to render the same LVGL UI.
- Connect the STM32F746G-DISCO board via the ST-LINK USB port to your Mac.
- Install a recent nightly "main" Swift toolchain. This is best done using
swiftly
, for example with:
$ swiftly install main-snapshot-2025-04-12
$ swiftly use main-snapshot-2025-04-12 -g
- Install the
stlink
(https://github.com/stlink-org/stlink) command line tools, e.g. viabrew install stlink
. - Run a provided shell script that fetches the LVGL and LLVM dependencies:
$ ./fetch-dependencies.sh
- Build the firmware by running make:
$ make
- Flash the built firmware by running make with the following target:
$ make flash
You should now see the UI animating on the board's LCD display, and the touch screen should react to inputs.
Optionally, you can also run build and run the code in a desktop OS SDL "simulator" by:
$ make simulator
- The ELF linking, linker script and packaging scheme is destribed in detail inside the linker script.