#Rust Building Erros
82 messages · Page 1 of 1 (latest)
please post the whole error
and possibly paste the relevant code here, because jumping between channels isn't very convenient
full error rust error[E0277]: the trait bound `avr_hal_generic::spi::Spi<Atmega, arduino_hal::pac::SPI, PB5, PB3, PB4, PB2>: embedded_hal::spi::SpiDevice` is not satisfied --> src/main.rs:22:27 | 22 | let bme = BME280::new(spi).unwrap(); | ----------- ^^^ the trait `embedded_hal::spi::SpiDevice` is not implemented for `avr_hal_generic::spi::Spi<Atmega, arduino_hal::pac::SPI, PB5, PB3, PB4, PB2>` | | | required by a bound introduced by this call | = help: the trait `embedded_hal::spi::SpiDevice<Word>` is implemented for `&mut T` note: required by a bound in `bme280::spi::BME280::<SPI>::new` --> /Users/tim/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bme280-0.5.1/src/spi.rs:56:10 | 56 | SPI: AsyncSpiDevice<Error = SPIE>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `BME280::<SPI>::new` ... 60 | pub fn new(spi: SPI) -> Result<Self, Error<SPIError<SPIE>>> { | --- required by a bound in this associated function my code ```rust
#![no_std]
#![no_main]
use panic_halt as _;
use bme280::spi::BME280;
use arduino_hal::prelude::*;
use arduino_hal::spi;
#[arduino_hal::entry]
fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let (spi, _) = arduino_hal::Spi::new(
dp.SPI,
pins.d13.into_output(),
pins.d11.into_output(),
pins.d12.into_pull_up_input(),
pins.d10.into_output(),
spi::Settings::default()
);
let bme = BME280::new(spi).unwrap();
loop {
arduino_hal::delay_ms(1000);
}
}
was there an example that you were following or something?
how did you come up with the let bme = BME280::new(spi).unwrap(); code?
i mean its very very very vague, there isnt really one for SPI only for IC2
this just going off there code and looking at how to do it, i dont see any SPI examples for BME280 sadly
can you try cargo tree -i embedded_hal?
impl<SPI, SPIE> AsyncBME280<SPI>
where
SPI: AsyncSpiDevice<Error = SPIE>,
// SPI::Buf: AsyncSpiBus<u8>,
{
/// Create a new BME280 struct
pub fn new(spi: SPI) -> Result<Self, Error<SPIError<SPIE>>> {
Ok(Self {
common: AsyncBME280Common {
interface: AsyncSPIInterface { spi },
calibration: None,
},
})
}
``` i saw this
thhats how i saw it returned self which is an SPI
sure i can try that
package ID specification embedded_hal did not match any packages
oh, huh
the documentation has none for SPI either
let (spi, _) = arduino_hal::Spi::new(
dp.SPI,
pins.d13.into_output(),
pins.d11.into_output(),
pins.d12.into_pull_up_input(),
pins.d10.into_output(),
spi::Settings::default()
);
``` this is called from ```rust
pub fn new(
p: SPI,
sclk: port::Pin<port::mode::Output, SCLKPIN>,
mosi: port::Pin<port::mode::Output, MOSIPIN>,
miso: port::Pin<port::mode::Input<port::mode::PullUp>, MISOPIN>,
cs: port::Pin<port::mode::Output, CSPIN>,
settings: Settings,
) -> (Self, ChipSelectPin<CSPIN>) {
let mut spi = Self {
p,
sclk,
mosi,
miso: miso.forget_imode(),
write_in_progress: false,
_cs: PhantomData,
_h: PhantomData,
};
spi.p.raw_setup(&settings);
(spi, ChipSelectPin(cs))
}
it seem very very odd
ah, it's with - and not _
shouldn't it say that?
i did do cargo tree -i embedded_hal and got ```error: package ID specification embedded_hal did not match any packages
then do embedded-hal
error: There are multiple `embedded-hal` packages in your project, and the specification `embedded-hal` is ambiguous.
Please re-run this command with one of the following specifications:
embedded-hal@0.2.7
embedded-hal@1.0.0
hmm
yeah that's what I suspected
cargo toml seems to have one
the trait and the struct are using different versions
it kinda should say that, there is a lint in the compiler which detects that, but not every case is covered, so sometimes you have to guess what's wrong
it's not supposed to change anything
it gives you a list of reverse dependencies
so you can see which crate has the outdated version
hmm ok
let me see here
mbedded-hal v0.2.7
├── arduino-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624)
│ └── ard v0.1.0 (/Users/tim/ard)
└── avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624)
├── arduino-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624) (*)
└── atmega-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624)
└── arduino-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=3e362624547462928a219c40f9ea8e3a64f21e5f#3e362624) (*)
may need to update the embedded-hal dependency
switched to 1.0.0 but seems not to fix it
so it seems my dependencies need 0.2.* versions but embedded hal moved on to 1.0.0
Hey there! I recently went to port one of my driver crates to the new [email protected], with its (honestly much nicer) APIs. However, I also wanted to check if my port worked on real hardwar...
i may just need to find new dependencies for bme
the problem is in arduino-hal
hmmm
odd
yea
do you see a fix in the post? i dont
technically arduino_hal is what should be used for SPI
look at his PR does not look like i needed to change anything on my part?
i did try adding [dependencies.embedded-hal-v0] version = "0.2.8" package = "embedded-hal" and that is referenced in the PR
you could try using https://docs.rs/embedded-hal-bus/0.2.0/embedded_hal_bus/spi/index.html to make the arduino_hal::spi::Spi into a embedded_hal::spi::SpiDevice as now it only implements embedded_hal::spi::SpiBus
I'm not sure if the PR (https://github.com/Rahix/avr-hal/pull/517) author intended to implement SpiDevice too
i tried messing with those earlier they are just traits
based on the arduino, i need th reference the SPI Struct and get new with the pins for the arduino
SpiDevice and SpiBus are just traits
which i dont think setting up my own to implement them would be ideal
I didn't say anything about implementing them
embedded-hal-bus I linked has implementations of SpiDevice when something already implements SpiBus
like arduino_hal::spi::Spi does
btw can you show your Cargo.toml?
sure thing
[package]
name = "ard"
version = "0.1.0"
authors = ["Tim Kotowski <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
[[bin]]
name = "ard"
test = false
bench = false
[dependencies]
panic-halt = "0.2.0"
ufmt = "0.2.0"
embedded-hal = "1.0.0"
nb = "0.1.2"
bme280 = "0.5.1"
[dependencies.arduino-hal]
git = "https://github.com/rahix/avr-hal"
rev = "3e362624547462928a219c40f9ea8e3a64f21e5f"
features = ["arduino-uno"]
# The latest releases of `proc-macro2` do not support the rust toolchain that
# we use. Thus, we must fix this dependency to an older version where our
# toolchain is still supported. See https://github.com/Rahix/avr-hal/issues/537
[build-dependencies.proc-macro2]
version = "=1.0.79"
# Configure the build for minimal size - AVRs have very little program memory
[profile.dev]
panic = "abort"
lto = true
opt-level = "s"
[profile.release]
panic = "abort"
codegen-units = 1
debug = true
lto = true
opt-level = "s"
[package]
name = "ard"
version = "0.1.0"
authors = ["Tim Kotowski <[email protected]>"]
edition = "2021"
license = "MIT OR Apache-2.0"
[[bin]]
name = "ard"
test = false
bench = false
[dependencies]
panic-halt = "0.2.0"
ufmt = "0.2.0"
embedded-hal = "1.0.0"
nb = "0.1.2"
bme280 = "0.5.1"
[dependencies.arduino-hal]
git = "https://github.com/rahix/avr-hal"
rev = "3e362624547462928a219c40f9ea8e3a64f21e5f"
features = ["arduino-uno"]
# The latest releases of `proc-macro2` do not support the rust toolchain that
# we use. Thus, we must fix this dependency to an older version where our
# toolchain is still supported. See https://github.com/Rahix/avr-hal/issues/537
[build-dependencies.proc-macro2]
version = "=1.0.79"
# Configure the build for minimal size - AVRs have very little program memory
[profile.dev]
panic = "abort"
lto = true
opt-level = "s"
[profile.release]
panic = "abort"
codegen-units = 1
debug = true
lto = true
opt-level = "s"
``` i changed `embedded-hal` it was 0.2.7
sorry it was embedded-hal = "0.2.3"
that's the same thing basically
ok so I'd try ^ that
for now
ty so much it build.
let dp = arduino_hal::Peripherals::take().unwrap();
let pins = arduino_hal::pins!(dp);
let delay = arduino_hal::Delay::new();
let mut delayOne = arduino_hal::Delay::new();
let (spi, cs) = arduino_hal::Spi::new(
dp.SPI,
pins.d13.into_output(),
pins.d11.into_output(),
pins.d12.into_pull_up_input(),
pins.d10.into_output(),
spi::Settings::default()
);
let mut spi_device = ExclusiveDevice::new(spi, cs, delay).unwrap();
let mut bme = BME280::new(spi_device).unwrap();
bme.init(&mut delayOne).unwrap();
loop {
arduino_hal::delay_ms(1000);
}
}
``` just seems odd i have to use delay twice since the first cant be a mutable reference
so now i gotta create a new delay for initialize the bme... which seems odd
but yeah
yeah, but it just seems like Delay doesn't have state, so you can freely create new ones 🤷♂️
anyway, I'm glad it works 
thanks man
i aprpeciate this alot.
coming back to rust for embedded and this is what i get, lmao
kill me
lol, embedded story in rust is quite messy still