最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

embedded - Rust en ESP32: "file not found for module arch" con esp-backtrace - Stack Overflow

programmeradmin6浏览0评论

I'm a student passionate about embedded systems, and I'm trying to program an ESP32 using Rust. I'm using esp-hal and esp-backtrace for error handling, but I'm encountering a compilation issue.

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_hal::{
    analog::adc::{Adc, AdcConfig, Attenuation},
    delay::Delay,
    gpio::{Level, Output, OutputConfig},
    main,
};
use log::{info, warn};
use nb::block; 

#[main]
fn main() -> ! {
    let peripherals = esp_hal::init(esp_hal::Config::default());
    esp_println::logger::init_logger_from_env();

    let mut led = Output::new(peripherals.GPIO4, Level::High, OutputConfig::default());

    // ADC
    let analog_pin = peripherals.GPIO32;
    let mut adc1_config = AdcConfig::new();
    let mut pin = adc1_config.enable_pin(
        analog_pin,
        Attenuation::_11dB,
    );
    let mut adc1 = Adc::new(peripherals.ADC1, adc1_config);

    // Delay
    let delay = Delay::new();

    info!("Start...");

    loop {
        // Intentar leer el ADC
        match block!(adc1.read_oneshot(&mut pin)) {
            Ok(pin_value) => {
                info!("ADC Value: {}", pin_value);

                // 
                if pin_value > 2000 {
                    led.set_high();
                } else {
                    led.set_low();
                }
            }
            Err(e) => {
                warn!("Error al leer el ADC: {:?}", e);
                // 
                led.set_high(); // 
            }
        }

        delay.delay_millis(500);
    }
}

this is my cargo.toml

[package]
name = "esp-32-project"
version = "0.1.0"
edition = "2021"

[dependencies]
esp-hal = { version = "1.0.0-beta.0", features = ["esp32", "unstable"] }
esp-backtrace = { version = "0.15.1", features = ["esp32", "panic-handler", "println"] }
esp-println = { version = "0.13.1", features = ["esp32", "log"] }
log = "0.4.26"
nb = "1.1"

Compilation Error: When I try to compile with cargo build, I get the following error:

error[E0583]: file not found for module `arch`
  --> C:\Users\Richard\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\esp-backtrace-0.15.1\src\lib.rs:46:1
   |
46 | pub mod arch;
   | ^^^^^^^^^^^^^
   |
   = help: to create the module `arch`, create file "C:\Users\Richard\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\esp-backtrace-0.15.1\src\arch.rs" or "C:\Users\Richard\.cargo\registry\src\arch\mod.rs"
   = note: if there is a `mod arch` elsewhere in the crate already, import it with `use crate::...` instead

Why is esp-backtrace unable to find the arch module? Am I missing a configuration in Cargo.toml or my code?

Any help would be greatly appreciated!

I tried running cargo build, but I got an error saying the arch module was missing.

I expected the code to compile successfully and upload to my ESP32.

To fix it, I tried:

Running cargo clean and then cargo build. Checking that esp-backtrace has the correct features enabled. Downgrading esp-backtrace to an older version. But the error persists. How can I fix this?

发布评论

评论列表(0)

  1. 暂无评论