rust-iot / rust-radio-sx127x

Rust driver for the Semtech SX127x series of Sub-GHz LoRa/ISM radio transceivers
Mozilla Public License 2.0
33 stars 17 forks source link

embedded-hal-1.0.0 examples update #129

Open pdgilbert opened 8 months ago

pdgilbert commented 8 months ago

Using @matheo-lucak 's fork of rust-radio-sx127x I finally have some examples compiling with embedded-hal-1.0.0 on stm32f4xx_hal and forks/branches of stm32g4xx_hal and stm32h7xx_hal. (Details are reported with other examples at https://github.com/pdgilbert/rust-integration-testing/actions . See jobs eg(lora_spi* in the workflow runs.)

The lora_spi_send and lora_spi_receive examples compile with all three hals. The lora_spi_gps example does not compile on stm32f4xx_hal because the embedded-io traits are not implemented. (See https://github.com/stm32-rs/stm32f4xx-hal/issues/721.) It compiles but probably does not work yet withstm32g4xx_hal and stm32h7xx_hal. I need to rework some logic for the change to embedded-io traits. Nothing has yet been tested on hardware.

One problem that I found subtle is the need for common versions for traits to work properly. In particular I had trouble with Transmit and Receive traits. For example, in my Cargo.toml I need

radio = { version = "0.11.1", git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" }
radio-sx127x  = {  git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false }

which specifies that the radio rev is the same as that used by radio-sx127x. If I do simple

radio         = { git = "https://github.com/rust-iot/radio-hal" } 
radio-sx127x  = { git = "https://github.com/matheo-lucak/rust-radio-sx127x", default-features = false }

the error messages can be very confusing:

Click to expand compiling error ``` ... error[E0599]: no method named `start_transmit` found for struct `Sx127x` in the current scope --> examples/radio-sx127x/lora_spi_send.rs:94:14 | 94 | lora.start_transmit(message).unwrap(); // should handle error | ^^^^^^^^^^^^^^ method not found in `Sx127x, ..., ..., ..., ..., ...>>` | ::: /home/paul/.cargo/git/checkouts/radio-hal-f38ece0492420e67/7aade85/src/lib.rs:39:8 | 39 | fn start_transmit(&mut self, data: &[u8]) -> Result<(), Self::Error>; | -------------- the method is available for ... help: the following trait is implemented but not in scope; perhaps add a `use` for it: | 45 + use radio::Transmit; | ... warning: unused import: `radio::Transmit` --> examples/radio-sx127x/lora_spi_send.rs:57:5 | 57 | use radio::Transmit; | ^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default ... ```

Is it possible radio-sx127x can re-export radio traits so I can manage this problem by using traites from radio-sx127x rather than from radio?

(BTW I have closed several old issues that are out-of-date. Thanks for all your help on those @ryankurte)

pdgilbert commented 4 months ago

The rust-iot/rust-radio-sx127x master branch seems to be stuck at embedded-hal-rc. I can compile @matheo-lucak 's fork embedded-hal-1.0 but am not having any luck getting it to work on hardware (using stm32f4xx_hal with blackpill stm32f411 and stm32g4xx_hal with weact-stm32g474). I forked it to try and debug with my examples, but no luck with that either.

Does anyone actually have this working? On what hardware? Any other suggestions? Thanks.