407 字
2 分钟
使用RustRover 2025.1.5及以下版本开发nRF MCU遇到的一些问题的处理办法

前面使用rust搭建nRF52832开发环境的时候发现一个问题:正常进行嵌入式开发的时候使用RustRover需要声明以下代码:

#![no_std]
#![no_main]

这里加这两行声明是因为使用nRF的HAL框架需要使用 #[cortex_m_rt::entry] 来标记main函数,编译器构建时会找不到目标main函数;且调试也不用std标准接口。

RustRover的编译器在执行build的时候会加入一些特殊的flag,导致代码检查时会报错:

Can’t find crate ‘test’

因为RustRover添加的flag导致cargo在build之前运行了test指令,但是针对嵌入式开发构建的目标显然不能在pc环境运行,所以我们需要在Cargo.toml文件中加入下面的代码:

[[bin]]
name = "nrf52832-sample"
test = false # 告诉Cargo本项目构建时不需要测试
bench = false

这里贴一段完整的Cargo配置文件做参考:

[package]
name = "nrf52832-sample"
version = "0.1.0"
authors = ["Martin Levine <lulingfeng@next5.studio>"]
edition = "2024"
[dependencies]
cortex-m = { version = "0.7.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7.5"
defmt = { git = "https://github.com/knurling-rs/defmt", branch = "main" }
defmt-rtt = { git = "https://github.com/knurling-rs/defmt", branch = "main" }
nrf52810-hal = "0.18.0"
smart-leds = "0.4.0"
[features]
# set logging levels here
default = [
"defmt-default",
]
# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
[[bin]]
name = "nrf52832-sample"
test = false
bench = false

除了上述代码以外还可以通过升级RustRover到最新的版本解决这个问题,但是最新的RustRover会有新的问题:编辑Cargo.toml的时候添加dependencies的智能补齐不生效。 <— 这个暂时找不到解决办法。

使用RustRover 2025.1.5及以下版本开发nRF MCU遇到的一些问题的处理办法
https://martinlevine.vercel.app/posts/resolve-rust-rover-s-problem/
作者
404 Not Found.
发布于
2025-09-08
许可协议
CC BY-NC-SA 4.0