首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用elf2uf2-rs在Raspberry Pi Pico上运行货物代码

使用elf2uf2-rs在Raspberry Pi Pico上运行货物代码
EN

Stack Overflow用户
提问于 2022-01-01 18:43:16
回答 1查看 992关注 0票数 2

我试着在Raspberry Pi Pico上运行Rust代码。使用以下方法成功构建了一个简单的“眨眼”例子应用程序(看上去是这样的):

代码语言:javascript
复制
cargo build --release --target=thumbv6m-none-eabi

我已将elf2uf2-rs安装如下:

代码语言:javascript
复制
cargo install elf2uf2-rs

然后,我尝试在Raspberry Pi Pico上运行眨眼应用程序,使用:

代码语言:javascript
复制
cargo run --release --target=thumbv6m-none-eabi

但是这个消息失败了,其中"rp2“是我的二进制文件的名称:

代码语言:javascript
复制
target/thumbv6m-none-eabi/release/rp2: cannot execute binary file

有什么可能出错的建议吗?

这是我的Cargo.toml

代码语言:javascript
复制
[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

代码语言:javascript
复制
# 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文件:

代码语言:javascript
复制
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命令将失败:

代码语言:javascript
复制
error: linking with `rust-lld` failed: exit status: 1
...
= note: rust-lld: error: cannot find linker script defmt.x

我使用MacBook和M1苹果硅芯片,这可能是一个相关的问题AArch64系统下的锈蚀-lld问题

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-02 09:17:23

我现在已经在Raspberry Pi Pico上运行了代码。

第一个问题是,我没有创建包含要使用.cargo/config.toml“运行”的指令的elf2uf2文件:

代码语言:javascript
复制
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "elf2uf2-rs -d"

另一个问题是,我的.cargo/config.toml还包含了对系统中没有的护卫的引用,所以当注释掉这一行时(在rustflags下),用cargo build --release编译的代码在带有cargo run --release的Raspberry Pi Pico上运行

代码语言:javascript
复制
# "-C", "link-arg=-Tdefmt.x",
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70551050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档