运行 使用 elf2uf2-rs 在 Raspberry Pi Pico 上使用 cargo 运行 的代码
Run code with cargo run on Raspberry Pi Pico using elf2uf2-rs
我尝试 运行 在 Raspberry Pi Pico 上编写 Rust 代码。一个简单的 "blink" example 应用程序成功构建(看起来)使用:
cargo build --release --target=thumbv6m-none-eabi
我安装了elf2uf2-rs:
cargo install elf2uf2-rs
然后我尝试 运行 Raspberry Pi Pico 上的闪烁应用程序使用:
cargo run --release --target=thumbv6m-none-eabi
但失败并显示此消息,其中“rp2”是我的二进制文件的名称:
target/thumbv6m-none-eabi/release/rp2: cannot execute binary file
有什么错误的建议吗?
这是我的 Cargo.toml
:
[package]
name = "rp2"
version = "0.1.0"
edition = "2021"
[dependencies]
rp2040-hal = "0.3.0"
cortex-m = "0.7.2"
embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { version="=1.0.0-alpha.6", package="embedded-hal", optional=true }
embedded-time = "0.12.0"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
cortex-m-rt = "0.7"
rp-pico = "0.2.0"
[dev-dependencies]
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
更新
我现在添加了一个包含以下内容的文件 .cargo/config.toml
:
# Choose a default "cargo run" tool.
# probe-run is recommended if you have a debugger
# elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# runner = "probe-run --chip RP2040"
runner = "elf2uf2-rs -d"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# Code-size optimizations.
# trap unreachable can save a lot of space, but requires nightly compiler.
# uncomment the next line if you wish to enable it
# "-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
]
[build]
target = "thumbv6m-none-eabi"
和一个包含以下内容的 memory.x
文件:
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
EXTERN(BOOT2_FIRMWARE)
SECTIONS {
/* ### Boot loader */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;
但是 cargo build --release
命令失败并出现此错误:
error: linking with `rust-lld` failed: exit status: 1
...
= note: rust-lld: error: cannot find linker script defmt.x
我使用配备 M1 Apple Silicon 芯片的 MacBook,这可能是一个相关问题 。
我现在在 Raspberry Pi Pico 上获得了密码 运行ning。
第一个问题是我没有创建 .cargo/config.toml
文件,其中包含使用 elf2uf2 的“运行”指令:
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"
另一个问题是我的 .cargo/config.toml
还包含对 defmt 的引用,我的系统中没有,所以在注释掉这一行时(在 rustflags
下) ,用 cargo build --release
编译的代码在 Raspberry Pi Pico 上是 运行,cargo run --release
:
# "-C", "link-arg=-Tdefmt.x",
我尝试 运行 在 Raspberry Pi Pico 上编写 Rust 代码。一个简单的 "blink" example 应用程序成功构建(看起来)使用:
cargo build --release --target=thumbv6m-none-eabi
我安装了elf2uf2-rs:
cargo install elf2uf2-rs
然后我尝试 运行 Raspberry Pi Pico 上的闪烁应用程序使用:
cargo run --release --target=thumbv6m-none-eabi
但失败并显示此消息,其中“rp2”是我的二进制文件的名称:
target/thumbv6m-none-eabi/release/rp2: cannot execute binary file
有什么错误的建议吗?
这是我的 Cargo.toml
:
[package]
name = "rp2"
version = "0.1.0"
edition = "2021"
[dependencies]
rp2040-hal = "0.3.0"
cortex-m = "0.7.2"
embedded-hal = { version = "0.2.5", features = ["unproven"] }
eh1_0_alpha = { version="=1.0.0-alpha.6", package="embedded-hal", optional=true }
embedded-time = "0.12.0"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
cortex-m-rt = "0.7"
rp-pico = "0.2.0"
[dev-dependencies]
cortex-m-rt = "0.7"
panic-halt = "0.2.0"
rp2040-boot2 = "0.2.0"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
更新
我现在添加了一个包含以下内容的文件 .cargo/config.toml
:
# Choose a default "cargo run" tool.
# probe-run is recommended if you have a debugger
# elf2uf2-rs loads firmware over USB when the rp2040 is in boot mode
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# runner = "probe-run --chip RP2040"
runner = "elf2uf2-rs -d"
rustflags = [
"-C", "linker=flip-link",
"-C", "link-arg=--nmagic",
"-C", "link-arg=-Tlink.x",
"-C", "link-arg=-Tdefmt.x",
# Code-size optimizations.
# trap unreachable can save a lot of space, but requires nightly compiler.
# uncomment the next line if you wish to enable it
# "-Z", "trap-unreachable=no",
"-C", "inline-threshold=5",
"-C", "no-vectorize-loops",
]
[build]
target = "thumbv6m-none-eabi"
和一个包含以下内容的 memory.x
文件:
MEMORY {
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100
RAM : ORIGIN = 0x20000000, LENGTH = 256K
}
EXTERN(BOOT2_FIRMWARE)
SECTIONS {
/* ### Boot loader */
.boot2 ORIGIN(BOOT2) :
{
KEEP(*(.boot2));
} > BOOT2
} INSERT BEFORE .text;
但是 cargo build --release
命令失败并出现此错误:
error: linking with `rust-lld` failed: exit status: 1
...
= note: rust-lld: error: cannot find linker script defmt.x
我使用配备 M1 Apple Silicon 芯片的 MacBook,这可能是一个相关问题
我现在在 Raspberry Pi Pico 上获得了密码 运行ning。
第一个问题是我没有创建 .cargo/config.toml
文件,其中包含使用 elf2uf2 的“运行”指令:
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"
另一个问题是我的 .cargo/config.toml
还包含对 defmt 的引用,我的系统中没有,所以在注释掉这一行时(在 rustflags
下) ,用 cargo build --release
编译的代码在 Raspberry Pi Pico 上是 运行,cargo run --release
:
# "-C", "link-arg=-Tdefmt.x",