使用 rtt-target crate 与 ST Nucleo-L152RE 时出现问题

问题描述 投票:0回答:1

这是我的代码,在我导入 rtt-target crate 并添加 rtt_init_print!(); 之后,当前无法编译。 rprintln!("你好,世界!"); 到节目

这是 Cargo.toml 文件

# Cargo.toml
[package]
edition = "2018"
name = "blinky-rust"
version = "0.1.0"

[profile.release]
opt-level = 'z' # turn on maximum optimizations. We only have 64kB
lto = true      # Link-time-optimizations for further size reduction

[dependencies]
cortex-m = "^0.6.3"      # Access to the generic ARM peripherals
cortex-m-rt = "^0.6.12"  # Startup code for the ARM Core
embedded-hal = "^0.2.4"  # Access to generic embedded functions (`set_high`)
panic-halt = "^0.2.0"    # Panic handler
rtt-target = "0.5.0"

# Access to the HAL.
[dependencies.stm32l1xx-hal]
features = ["stm32l151", "rt"]
version = "^0.0.1"

这是main.rs文件

# main.rs
#![no_main]
#![no_std]

use panic_halt as _;

use cortex_m_rt::entry;
use stm32l1xx_hal::delay::Delay;
use stm32l1xx_hal::gpio::GpioExt;
use stm32l1xx_hal::hal::digital::v2::OutputPin;
use stm32l1xx_hal::rcc::{Config, RccExt};
use stm32l1xx_hal::stm32::Peripherals;
use stm32l1xx_hal::stm32::CorePeripherals;
use stm32l1xx_hal::time::MicroSeconds;

use rtt_target::{rtt_init_print, rprintln};

#[entry]
fn main() -> ! {
    rtt_init_print!();

    let p = Peripherals::take().unwrap();
    let cp = CorePeripherals::take().unwrap();

    // Get LED pin PB6
    let gpioa = p.GPIOA.split();
    let mut led = gpioa.pa5.into_push_pull_output();

    // Set up a delay
    let rcc = p.RCC.freeze(Config::default());
    let mut delay = Delay::new(cp.SYST, rcc.clocks);

    loop {
        rprintln!("Hello, world!"); 

        // Turn LED On
        led.set_high().unwrap();

        delay.delay(MicroSeconds(2_000_000_u32));

        // Turn LED Off
        led.set_low().unwrap();

        delay.delay(MicroSeconds(1_000_000_u32));
    }
}

这是 Embed.toml

# Embed.toml

[default.general]
chip = "STM32L152RE"

[default.rtt]
enabled = true

[default.probe]
protocol = "Swd"

[default.gdb]
enabled = false

问题,

cargo build
失败了:

   Compiling blinky-rust v0.1.0 (/home/alex/projects/cortex-m-quickstart)
error: linking with `arm-none-eabi-ld` failed: exit status: 1
     = note: arm-none-eabi-ld: /home/alex/projects/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/librtt_target-df1e3f299aa0549b.rlib(rtt_target-df1e3f299aa0549b.rtt_target.1a0c5dea5ce969ca-cgu.0.rcgu.o): in function `critical_section::acquire':
          /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/lib.rs:183: undefined reference to `_critical_section_1_0_acquire'
          arm-none-eabi-ld: /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/lib.rs:183: undefined reference to `_critical_section_1_0_acquire'
          arm-none-eabi-ld: /home/alex/projects/cortex-m-quickstart/target/thumbv7m-none-eabi/debug/deps/librtt_target-df1e3f299aa0549b.rlib(rtt_target-df1e3f299aa0549b.rtt_target.1a0c5dea5ce969ca-cgu.0.rcgu.o): in function `critical_section::release':
          /home/alex/.cargo/registry/src/index.crates.io-6f17d22bba15001f/critical-section-1.1.2/src/lib.rs:200: undefined reference to `_critical_section_1_0_release'

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `blinky-rust` (bin "blinky-rust") due to previous error

我尝试使用 rtt-target 查看 ST Nucleo-L152RE 的日志

rust embedded
1个回答
0
投票

我必须补充一下

cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }

到 Cargo.toml,现在可以了

© www.soinside.com 2019 - 2024. All rights reserved.