Skip to content

嵌入式

Slint 可在许多嵌入式平台上运行。

下面的平台描述涵盖了已针对部署测试过的内容。对于开发环境, 我们建议使用较新的桌面操作系统和编译器版本。

Slint 可在多种嵌入式 Linux 平台上运行。一般来说,Slint 需要一个现代的 Linux 用户空间, 并具备可用的 OpenGL ES 2.0(或更新版本)或 Vulkan 驱动。我们已成功在以下平台上运行 Slint:

  • 基于 Yocto 的发行版。
  • 基于 BuildRoot 的发行版。
  • Torizon。

对于 C++ 应用程序,请参见 meta-slint 获取 recipe。

Rust 应用程序在 Yocto 的 Rust 支持下开箱即用。

Slint 的平台抽象允许集成到任何基于 Rust 或 C++ 的微控制器开发 环境中。开发者需要实现相应功能来馈送诸如触摸或键盘之类的输入事件, 以及把 Slint 渲染的像素显示到一个帧缓冲或行缓冲中。

你需要使用 mcu-board-support crate。这个 crate 重新导出了一个应用于 main 函数的 entry 属性宏,以及一个应在 创建 Slint UI 之前调用的 init() 函数。

为了使用这个后端,最终程序必须同时依赖 slint 和 mcu-board-support。 main.rs 看起来大致像这样

#![no_std]
#![cfg_attr(not(feature = "simulator"), no_main)]
slint::include_modules!();
#[allow(unused_imports)]
use mcu_board_support::prelude::*;
#[mcu_board_support::entry]
fn main() -> ! {
mcu_board_support::init();
MainWindow::new().run();
panic!("The event loop should not return");
}
rust

由于 mcu-board-support 目前是一个尚未上传到 crates.io 的内部 crate,你必须 使用 slint、slint-build 和 mcu-board-support 的 git 版本

[dependencies]
slint = { git = "https://github.com/slint-ui/slint", default-features = false }
mcu-board-support = { git = "https://github.com/slint-ui/slint" }
# ...
[build-dependencies]
slint-build = { git = "https://github.com/slint-ui/slint" }
toml

在你的 build.rs 中,必须包含对 slint_build::print_rustc_flags().unwrap() 的调用,以设置其中一些标志。

下面的 Rust 章节展示如何在各种开发板上运行 Slint Printer 演示程序。这些命令 应从 Slint 仓库的一次检出根目录运行; 该演示程序位于 demos Cargo 工作区中,因此需要显式的 --manifest-path。

使用 espflash 烧录时,系统会提示你选择一个 USB 端口。如果该端口总是相同的,那么你也可以在命令行上把它作为参数传入,以避免该提示。例如,如果 /dev/ttyUSB1 是你端口的设备文件,则命令行变为 espflash --monitor /dev/ttyUSB1 path/to/binary/to/flash_and_monitor。

要编译并运行 Slint Printer 演示程序:

Terminal window
CARGO_PROFILE_RELEASE_OPT_LEVEL=s cargo +esp run --manifest-path demos/printerdemo_mcu/Cargo.toml --target xtensa-esp32s3-none-elf --no-default-features --features=mcu-board-support/esp32-s3-box-3 --release --config examples/mcu-board-support/esp32_s3_box_3/cargo-config.toml
bash

遵循以下步骤运行 Slint Printer 演示程序

使用 probe-rs。

Terminal window
CARGO_PROFILE_RELEASE_OPT_LEVEL=s CARGO_TARGET_THUMBV7EM_NONE_EABIHF_RUNNER="probe-rs run --chip STM32H735IGKx" cargo run --manifest-path demos/printerdemo_mcu/Cargo.toml --no-default-features --features=mcu-board-support/stm32h735g --target=thumbv7em-none-eabihf --release
bash

目前在 Raspberry Pi Pico 上仅支持 Rust 程序。

确保设置了正确的目标:

Terminal window
rustup target add thumbv6m-none-eabi
bash

用以下命令构建 Slint Printer 演示程序:

Terminal window
cargo build --manifest-path demos/printerdemo_mcu/Cargo.toml --no-default-features --features=mcu-board-support/pico-st7789 --target=thumbv6m-none-eabi --release
bash

生成的文件可以用 elf2uf2-rs 烧录。使用以下命令安装它:

Terminal window
cargo install elf2uf2-rs
bash

现在关闭 Pico 的电源,并在按住“bootsel”按钮的同时连接它。该设备会显示为一个存储设备, 名称为 RPI-RP2。

然后用以下命令把演示程序烧录到 Pico:

Terminal window
elf2uf2-rs -d target/thumbv6m-none-eabi/release/printerdemo_mcu
bash

烧录完成后,Pico 会重启并显示 Slint Printer 演示程序。Mac 会 警告驱动器被意外卸载。这是预期行为,可以忽略。

用以下命令构建 Slint Printer 演示程序:

Terminal window
cargo build --manifest-path demos/printerdemo_mcu/Cargo.toml --no-default-features --features=mcu-board-support/pico2-st7789 --target=thumbv8m.main-none-eabihf --release
bash

生成的文件可以用 picotool 方便地烧录。你应当从源代码构建它。

然后把演示程序上传到 Raspberry Pi Pico:连接 micro-usb 线缆到设备时,按住设备上的白色“bootsel”按钮, 这会在你的工作站上挂载一些 USB 存储,你可以把二进制文件存放进去。

或者在 linux 上通过命令(在按住“bootsel”按钮的同时连接设备):

Terminal window
# If you're on Linux: mount the device
udisksctl mount -b /dev/sda1
# upload
picotool load -u -v -x -t elf target/thumbv8m.main-none-eabihf/release/printerdemo_mcu
bash

这需要 probe-rs,并通过一个探针连接 pico (例如另一个运行探针的 pico)。

然后你就可以直接用 cargo run 运行

Terminal window
CARGO_TARGET_THUMBV6M_NONE_EABI_LINKER="flip-link" CARGO_TARGET_THUMBV6M_NONE_EABI_RUNNER="probe-rs run --chip RP2040" cargo run --manifest-path demos/printerdemo_mcu/Cargo.toml --no-default-features --features=mcu-board-support/pico-st7789 --target=thumbv6m-none-eabi --release
bash

使用 probe-rs 的 VSCode 插件烧录和调试 Pico

Section titled “使用 probe-rs 的 VSCode 插件烧录和调试 Pico”

按照此处的说明安装 probe-rs-debugger 和 VSCode 插件。

将此构建任务添加到你的 .vscode/tasks.json:

{
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"command": "build",
"args": [
"--manifest-path=demos/printerdemo_mcu/Cargo.toml",
"--features=mcu-pico-st7789",
"--target=thumbv6m-none-eabi",
"--profile=release-with-debug"
],
"problemMatcher": ["$rustc"],
"group": "build",
"label": "build mcu demo for pico"
}
]
}
json

需要 release-with-debug profile,因为 debug 构建无法装入 flash。

你可以在 demos/Cargo.toml 工作区清单中这样定义它:

[profile.release-with-debug]
inherits = "release"
debug = true
toml

现在你可以把启动配置添加到 .vscode/launch.json:

{
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "build mcu demo for pico",
"type": "probe-rs-debug",
"request": "launch",
"name": "Flash and Debug MCU Demo",
"cwd": "${workspaceFolder}",
"connectUnderReset": false,
"chip": "RP2040",
"flashingConfig": {
"flashingEnabled": true,
"resetAfterFlashing": true,
"haltAfterReset": true
},
"coreConfigs": [
{
"coreIndex": 0,
"rttEnabled": true,
"programBinary": "./target/thumbv6m-none-eabi/release-with-debug/printerdemo_mcu"
}
]
}
]
}
json

这是使用第二个 Raspberry Pi Pico 刷入 DapperMime 作为探针进行测试的。

如果你想在其他平台/版本上使用 Slint,请联系我们。


© 2026 SixtyFPS GmbH