项目结构
为你的具体应用配置 embassy 及其组件有很多方法。每个芯片组的 examples 目录演示了你的项目结构应该是什么样子。让我们来分解一下:
你的项目顶层文件结构应该如下所示:
{} = Maybe
my-project
|- .cargo
| |- config.toml
|- src
| |- main.rs
|- build.rs
|- Cargo.toml
|- {memory.x}
|- rust-toolchain.toml
[discrete]
.cargo/config.toml
此目录/文件描述了你所处的平台,并配置了 probe-rs 以部署到你的设备。
这是一个最小的例子:
[target.thumbv6m-none-eabi] # <- 为你的平台更改
runner = 'probe-rs run --chip STM32F031K6Tx' # <- 为你的芯片更改
[build]
target = "thumbv6m-none-eabi" # <- 为你的平台更改
[env]
DEFMT_LOG = "trace" # <- 可以更改为 info, warn, 或 error
[discrete]
build.rs
这是你项目的构建脚本。它链接了 defmt (什么是 defmt?) 和 memory.x
文件(如果需要)。此文件对于每个芯片组都非常具体,只需从相应的 example 复制粘贴即可。
[discrete]
Cargo.toml
这是你的清单文件,你可以在其中配置所有 embassy 组件以使用你所需的功能。
[discrete]
功能特性
[discrete]
时间
- tick-hz-x: 配置
embassy-time
的 tick 速率。更高的 tick 速率意味着更高的精度和更高的 CPU 唤醒频率。 - defmt-timestamp-uptime: defmt 日志条目将显示以秒为单位的运行时间。
...更多内容即将到来
[discrete]
memory.x
此文件概述了你的程序的 flash/ram 使用情况。当在 nRF5x 上使用 nrf-softdevice 时,它尤其有用。
这是一个在 nRF52840 上使用 S140 的示例:
MEMORY
{
/* NOTE 1 K = 1 KiBi = 1024 bytes */
/* 这些值对应于带有 Softdevices S140 7.0.1 的 NRF52840 */
FLASH : ORIGIN = 0x00027000, LENGTH = 868K
RAM : ORIGIN = 0x20020000, LENGTH = 128K
}
[discrete]
rust-toolchain.toml
此文件配置要使用的 rust 版本和配置。
一个最小的例子:
[toolchain]
channel = "nightly-2023-08-19" # <- 截至撰写本文时,这是 embassy 使用的确切 rust 版本
components = [ "rust-src", "rustfmt" ] # <- 可选地添加 "llvm-tools-preview" 以获得一些额外的功能,如 "cargo size"
targets = [
"thumbv6m-none-eabi" # <- 为你的平台更改
]