slint/examples/mcu-embassy
Olivier Goffart 59ac3ac599
Some checks are pending
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / fmt_test (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / node_test (macos-14) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
Update MSRV to 1.85
2025-06-26 22:50:15 +02:00
..
.cargo Remormat all the toml file again to fix npm upload 2025-04-09 15:06:00 +02:00
.vscode Add embassy microcontroller example demonstrating async 2025-02-10 16:56:15 +01:00
slint_generated Update MSRV to 1.85 2025-06-26 22:50:15 +02:00
src Fix embassy build after dependency updates 2025-04-23 14:11:22 +02:00
ui Updated copyright notice and embassy dependency 2025-02-10 16:56:15 +01:00
.gitignore Fixed issue with conflicting embassy-time-driver 2025-02-10 16:56:15 +01:00
Cargo.toml Update MSRV to 1.85 2025-06-26 22:50:15 +02:00
README.md Update mcu-embassy dependencies 2025-04-23 13:28:23 +02:00

Embassy Slint stm32u5g9j-dk2 Demo

An embedded async Slint GUI demo using Embassy and an stm32u5g9j-dk2 development kit. This demo was written to run on a resource constrained device, not a PC or laptop. The simulator can run on a PC if you do not have the dev kit on hand but it is not meant to be a reference design for an async GUI implementation on a PC.

The stm32u5g9j-dk2 was chosen because of its availability and price point and has enough onboard ram (3MB) and flash (4MB) to run Slint without external psram and flash, reducing setup complexity. It comes with a 5" 800x480 IPS touchscreen display. Async is useful for building more complex UIs because you don't have to hand code your own state machines.

Things that are demonstrated here:

  • Sending rendered display buffer to LCD screen asynchronously freeing up the mcu to do other things
  • Responding to hardware events (pressing the USER button on the DK2 changes the colour of the grey circle to blue)
  • Touchscreen actions setting physical hardware (toggling the switch on the touchscreen to turn on the green led on the DK2)
  • Cooperative multitasking (red led continues to flash on a separate task regardless of UI actions)
  • UI animations work
  • The application can be simulated on a PC without having to download to the DK2 every time you want to test something

Installation instructions

Install the cross compilation target for the mcu:

rustup target add thumbv8m.main-none-eabihf

You need software to be able to flash the firmware to the dev kit.

cargo install --force --locked probe-rs-tools

Running the application

Plug a usbc cable into the ST-LINK port on the dk2 and run the following:

cargo run -p mcu-embassy --bin ui_mcu --release --features=mcu

Troubleshooting:

If you are getting some complication errors from cortex-m like "error: invalid register r1: unknown register" make sure that you are cross compiling for the correct cpu target:

You can specify the target in the cargo run command in the following file:

In .cargo/Cargo.toml

[build]
target = "thumbv8m.main-none-eabihf"

If using vscode then make sure rust-analyzer.cargo.features is set to mcu in .vscode/settings.json

You may be wondering why you get the following message in the logs: invalid location: defmt frame-index In the Slint workspace Cargo.toml file overrides the Cargo.toml file in this crate so make sure the release profile is as follows in that workspace file:

[profile.release]
debug = true    # required for decent panic messages and log line locations
opt-level = "s"
lto = "thin"

Running the simulator

Of course you can use Slint's vscode plugin to preview slint files but you may want to actually run your application and simulate the hardware interactions. The simulator runs Embassy on the host machine (instead of on an mcu) and renders to the screen using the sdl2 library. Hardware like leds and buttons are emulated in the hardware module.

To install SDL2 follow the instructions here: https://github.com/Rust-SDL2/rust-sdl2

To run the simulator on a pc:

# for linux
cargo run -p mcu-embassy --bin ui_simulator --release --no-default-features --features=simulator --target x86_64-unknown-linux-gnu
# for windows
cargo run -p mcu-embassy --bin ui_simulator --release --no-default-features --features=simulator --target x86_64-pc-windows-msvc
# for mac
cargo run -p mcu-embassy --bin ui_simulator --release --no-default-features --features=simulator --target x86_64-apple-darwin

Note: Instead of specifying a target you can simply remove the arm target in .cargo/config.toml and cargo will use the host by default

Troubleshooting:

If you are getting some compilation errors from arrayvec like "error: requires sized lang_item" make sure you are NOT targeting the mcu when building for your pc.

Set the target correctly in the command line or comment out the following:

In .cargo/Cargo.toml

#[build]
#target = "thumbv8m.main-none-eabihf"

If using vscode then make sure rust-analyzer.cargo.features is set to simulator in .vscode/settings.json