Giter Site home page Giter Site logo

rust-iot / rust-radio-sx127x Goto Github PK

View Code? Open in Web Editor NEW
32.0 2.0 16.0 228 KB

Rust driver for the Semtech SX127x series of Sub-GHz LoRa/ISM radio transceivers

License: Mozilla Public License 2.0

Rust 99.85% C 0.15%
rust embedded radio sx127x driver lora sub-ghz semtech

rust-radio-sx127x's Introduction

rust-radio-sx127x

A primarily rust driver (and command line utility) for the Semtech SX1276 sub ghz ISM band radio IC.

Status

WIP. Basic LoRa functionality working.

GitHub tag Build Status BuildKite Build Status Crates.io Docs.rs Snap Status

Open Issues

Usage

Add to your project with cargo add radio-sx127x

Install the utility with one of the following methods:

  • using a pre-packaged snap with snap install sx127x-util
  • using a precompiled binary from the releases page
  • from source using cargo with cargo install radio-sx127x

As a no_std Library

The radio-sx127x crate can be used as an interface library for the sx127x radio on other embedded devices. To enable no_std usage, add default-features = false to your Cargo.toml

Useful Resources

rust-radio-sx127x's People

Contributors

berkowski avatar blinkystitt avatar dependabot[bot] avatar ryankurte avatar ryankurtedm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rust-radio-sx127x's Issues

Question: SPI settings Raspberry Pi 3 B+ Lora HAT

I am new to embedded, I hope it is ok to ask here, I have so much information and I can't figure out how it all relates. I am hoping to get some pointer that helps me to connect the information. I am trying to find out how the settings:

  • cs pin
  • rst pin
  • busy pin

translate to the information from the Lora HAT [1] From their sample code that works and runs with WiringPI [2] I get these pin numbers:

int ssPin = 6;
int dio0  = 7;
int RST   = 0;
  • I learned that nss, ss, ssPin, ce (chip enable) and cs (chip select) is the same thing. So it got one pin number, but I don·'t know if the numbering is the same.

  • I assume that RST is reset

  • This leaves dio0 to be busy??

The names the lora HAT uses in documentation is

  • Lora DIO0
  • Lora RESET
  • Lora NSS
  • Lora SCK

The biggest problem is, every subsystem numbers the pins different. See image:

image

Does the kernel translate the pin numbers too? I mean we access SPI via kernel device.

I converted the numbers in many way from most reasonable to some strange ways. What ever I do there are two outcomes

  • InvalidDevice (After that, the sx127x still works with the C program)
  • ResourceBusy (The sx127x is bricked and I have to reboot)

image

I also read about SPI and naming conventions didn't completely match neither rust-radio-sx127x nor one used in the Lora HAT.

[1] http://wiki.dragino.com/index.php?title=Lora/GPS_HAT
[2] http://wiringpi.com/

Type issue with stm32l1xx_hal

I try to use the driver with the stm32l1xx_hal

I have my Pins:

    let csPin = gpiob.pb0.into_push_pull_output();
    let busyPin = gpiob.pb8.into_floating_input();
    let sdnPin = gpioa.pa2.into_push_pull_output();

But when passing it into the driver:

    let mut hal = SpiWrapper::new(spi, csPin, delay);
    hal.with_busy(busyPin.downgrade());
    hal.with_reset(sdnPin.downgrade());

with_busy and with_reset both expect the same type Output but busyPin is of type PB0 and ´sdnPin´ is of type PA2. Even the downgrade just results in PA and PB which leads to a compile error.

Is it an issue with the stm32l1xx_hal or with the SX driver? Or is there any way I can convert / wrap my types to solve the issue?

cargo build --no-default-features fails

The crate fails to build with default features disabled (as required for use in no_std crates):

rust-radio-sx127x> cargo build --no-default-features
    Updating crates.io index
   Compiling proc-macro2 v1.0.8
   Compiling unicode-xid v0.2.0
   Compiling syn v1.0.14
   Compiling log v0.4.8
   Compiling cfg-if v0.1.10
   Compiling nb v0.1.2
   Compiling void v1.0.2
   Compiling bitflags v1.2.1
   Compiling serde v1.0.104
   Compiling libc v0.2.66
   Compiling embedded-hal v0.2.3
   Compiling embedded-spi v0.5.8
   Compiling quote v1.0.2
   Compiling async-trait v0.1.24
   Compiling serde_derive v1.0.104
   Compiling radio v0.4.4
   Compiling radio-sx127x v0.10.0 (/home/zac/Repos/rust-radio-sx127x)
error[E0599]: no method named `round` found for type `f32` in the current scope
   --> src/fsk.rs:148:64
    |
148 |         let fdev = ((channel.fdev as f32) / device::FREQ_STEP).round() as u32;
    |                                                                ^^^^^ method not found in `f32`

error[E0599]: no method named `round` found for type `f32` in the current scope
   --> src/fsk.rs:149:75
    |
149 |         let datarate = (self.config.xtal_freq as f32 / channel.br as f32).round() as u32;
    |                                                                           ^^^^^ method not found in `f32`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `radio-sx127x`.

To learn more, run the command again with --verbose.

Last working tag appears to be 0.7.4, where plain integer truncation was used for fdev and datarate, e.g.

let fdev = ((channel.fdev as f32) / device::FREQ_STEP) as u32;

If rounding is absolutely required it can be provided by the libm crate with some compile-time configuration.

dependencies on version of radio confuse embedded-hal-compat

(Mentioned in #34, but unclear about details.) rust-radio-sx127x dependencies on the version of radio confuse embedded-hal-compat

Version 0.10.1 of radio-sx127x on crates.io uses radio "0.4.0" . This does not work with embedded-hal-compat. The builds fail with wrong number of arguments, with or without

[patch.crates-io]
radio = { git = "https://github.com/ryankurte/rust-radio.git", branch = "master" }

Version 0.10.1 of radio-sx127x on https://github.com/rust-iot/rust-radio-sx127x uses radio "0.7.0" and my fork with the PR adding examples uses radio "0.8.1" . A crate using these needs to use the same version:

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

or

radio-sx127x  = {  git = "https://github.com/pdgilbert/rust-radio-sx127x", default-features = false }
radio         = { version = "0.8.1" }

The patch above has no affect on build for either (but I have not tested running). Is it possible the patch is no longer needed for anything?

Some consolidation would be good.

LoRa examples and testing

I forked rust-radio-sx127x just before the "update everything" commit so I could add examples I had working with embedded-hal 0.2.4. In the branch testing-e-h_0.2.4 I have added in examples/ the files lora_spi_gps.rs, lora_spi_receive.rs, and lora_spi_send.rs. The last has comments documenting how to build and run all three examples. These examples build on MCUs stm32f042, stm32f030xc, stm32f103, stm32f100, stm32f101, stm32f303xc stm32f401, stm32f411, stm32h742, stm32l100, and stm32l151 with the appropriate hal crates stm32f0xx-hal, stm32f1xx-hal, stm32f3xx-hal, stm32f4xx-hal, stm32h7xx-hal, and stm32l1xx-hal. I have run tested them on a bluepill (stm32f103) and blackpill (stm32f411) and they work.

The builds are automatically tested in workflow and reported at https://github.com/pdgilbert/rust-radio-sx127x/actions. These checks are done with release versions of the hals, but similar examples are run with git versions of the hals and reported at https://pdgilbert.github.io/eg_stm_hal/#table-of-additional-examples-status.

The directory memoryMaps and file build.rs are added to provide memory.x for linking, along with file openocd.gdb and some additions to .cargo/config so run testing can be done easily.

This "issue" was opened to record progress, for anyone interested, and because I am going to have questions and issues as I move forward and try to shift to embedded-hal 1.0.0-alpha. Also, please report here any problems or improvements in the examples, and any results from testing them with other MCUs.

Licensing terms?

I love this crate, but the licensing terms don't appear to be explicit. Can you clarify what they are?

Question: Integration testing example

I have trouble getting the integration test to work. I have two radios hooked up to the SPI0 bus on a Raspberry Pi and I can use both of them (but not at the same time) with the sx127x-util tool without problems.

If I try the integration test, the first radio setup succeeds but the second fails due to zero ("0") version (just assuming this means nothing is going on at the SPI bus).

If I swap the radios in the config, then same thing happens ("second" radio succeeds and "first" one fails). It seems to me like the SPI bus doesn't like me using two radios at once, yet that seems to be the case in the checked in version.

I also tried running two sx127x-util commands (one tx, one rx) but then "funny" things happen, probably due to no bus synchronization.

The reason I care is that I want to reuse this great idea of having an integration test for a new sx1231 driver, which is written on top of rust-radio-hal :)

Any ideas? Someone ran into issues before with SPI on RPi?

example cannot find its own crate

I was trying to change too much at once and it was shaking my sanity. Before attempting the compat layer I thought I would go back to a point I had working and try to put my example in my rust-radio-sx127x fork. So I branched just before "update everything" and have been trying to add it. But I cannot get the example code to find the modules of the crate it is in. I've tried referring to it as both radio_sx127x and as crate, and hundreds of other variations with no luck:

error[E0433]: failed to resolve: maybe a missing crate `radio_sx127x`?
  --> examples/lora_spi_send.rs:31:5
   |
31 | use radio_sx127x::{prelude::Error, prelude::Sx127x};
   |     ^^^^^^^^^^^^ maybe a missing crate `radio_sx127x`?

error[E0433]: failed to resolve: maybe a missing crate `device`?
  --> examples/lora_spi_send.rs:34:13
   |
34 | use crate::{device::lora::{LoRaConfig, LoRaChannel, Bandwidth, SpreadingFactor, CodingRate,
   |             ^^^^^^ maybe a missing crate `device`?

I've also tried adding it to its own Cargo.toml with no luck, and tried changing the directory name from rust-radio-sx127x to radio-sx127x just in case there was confusion between the crate name and the directory name, also with no luck.

The example does work outside the radio_sx127x crate as reported at https://pdgilbert.github.io/eg_stm_hal/#table-of-additional-examples-status and I have put examples in other crates, where I simply used use with the crate name like would be done normally to use it, and no need to add it to Cargo.toml.

Any suggestions?

embedded-hal-1.0.0 examples update

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 stm32-rs/stm32f4xx-hal#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<Base<Spi<SPI1>, ..., ..., ..., ..., ...>>`
   |
  ::: /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)

embedded-hal version conflicts

I seem to have fallen into dependency version hell with the switch to embedded-hal 1.0.0-alpha.4. I think the main problem is that the spi setup using stm32f4xx_hal, which still uses embedded-hal 0.2.4, does not mix well with the Sx127x::spi() use of the spi. One problem was that the mode argument for stm32f4xx_hal::spi::Spi::spi1 wants the older version. I fixed this by importing these from stm32f4xx_hal rather than from embedded-hal. (I suppose that is probably the correct way to do it anyway.)

The next problem I think is related but I don't really understand it. There is lots of trouble satisfying traits and I think this is because of the mix of embedded-hal versions being used in the call

       let lora = Sx127x::spi(
    	    spi,                                                       //Spi
    	    gpioa.pa1.into_push_pull_output(),                         //CsPin         on PA1
    	    gpiob.pb8.into_floating_input(),                           //BusyPin  DI00 on PB8
            gpiob.pb9.into_floating_input(),                           //ReadyPin DI01 on PB9
    	    gpioa.pa0.into_push_pull_output(),                         //ResetPin      on PA0
    	    delay,					               //Delay
    	    &CONFIG_RADIO,					       //&Config
    	    ).unwrap();     

Sx127x::spi is using the new version of embedded-hal while spi, is set up with the old version.

I have tried to get this to work two different ways, one with my usual setup which allows me to specify the version of embedded-hal my code uses, and the other by forking rust-radio-sx127x and putting an example in an examples-testing branch at https://github.com/pdgilbert/rust-radio-sx127x. (BTW, I am confused about whether the push of a branch on my fork automatically made a pull request upstream. If so, I did not intend to do that yet.) The latter way seems to force using the same embedded-hal as specified in the crate. Trying to build the example forced some Cargo.toml changes in the branch of the fork. Most notably I had to comment out the color-backtrace dependency because I could not get it to stop looking for std and thus failing. (Possibly there are other more notable changes that I don`t recognize which are causing the example build failure?)

The example has been stripped down to remove the setup() function that causes additional difficulties, and some warnings are caused by not using imports for that. Possibly InputPin and OutputPin are getting messed up by no longer having a v2 reference? The error seem to be pretty much the same for the two different ways:

Build output ``` $ cargo build --target thumbv7em-none-eabihf --no-default-features --features="stm32f411, stm32f4xx" --example lora_spi_send Compiling radio-sx127x v0.10.1 (/home/paul/githubClones/rust-radio-sx127x) warning: unused import: `blocking::delay::DelayMs` --> examples/lora_spi_send.rs:36:20 | 36 | use embedded_hal::{blocking::delay::DelayMs, | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

warning: unused import: Error as WrapError
--> examples/lora_spi_send.rs:41:50
|
41 | use driver_pal::{wrapper::Wrapper as SpiWrapper, Error as WrapError};
| ^^^^^^^^^^^^^^^^^^

warning: unused import: radio_sx127x::Error as sx127xError
--> examples/lora_spi_send.rs:47:5
|
47 | use radio_sx127x::Error as sx127xError; // Error name conflict with hals
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>: embedded_hal::blocking::spi::transfer::Default<u8> is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::blocking::spi::transfer::Default<u8> is not implemented for stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>
|
help: trait impl with same name found
--> /home/paul/.cargo/git/checkouts/stm32f4xx-hal-fe8350cc04cacf3f/4b04112/src/spi.rs:1072:1
|
1072 | / impl<SPI, PINS> embedded_hal::blocking::spi::transfer::Default for Spi<SPI, PINS> where
1073 | | SPI: Deref<Target = spi1::RegisterBlock>
1074 | | {
1075 | | }
| |_^
= note: perhaps two different versions of crate embedded_hal are being used?
= note: required because of the requirements on the impl of embedded_hal::blocking::spi::Transfer<u8> for stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>: embedded_hal::blocking::spi::write::Default<u8> is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::blocking::spi::write::Default<u8> is not implemented for stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>
|
help: trait impl with same name found
--> /home/paul/.cargo/git/checkouts/stm32f4xx-hal-fe8350cc04cacf3f/4b04112/src/spi.rs:1077:1
|
1077 | / impl<SPI, PINS> embedded_hal::blocking::spi::write::Default for Spi<SPI, PINS> where
1078 | | SPI: Deref<Target = spi1::RegisterBlock>
1079 | | {
1080 | | }
| |_^
= note: perhaps two different versions of crate embedded_hal are being used?
= note: required because of the requirements on the impl of embedded_hal::blocking::spi::Write<u8> for stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>: embedded_hal::blocking::spi::transactional::Default<u8> is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::blocking::spi::transactional::Default<u8> is not implemented for stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>
|
= note: required because of the requirements on the impl of embedded_hal::blocking::spi::Transactional<u8> for stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>: embedded_hal::digital::OutputPin is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::digital::OutputPin is not implemented for stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>
|
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>: embedded_hal::digital::InputPin is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::digital::InputPin is not implemented for stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>
|
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>: embedded_hal::digital::InputPin is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::digital::InputPin is not implemented for stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>
|
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>: embedded_hal::digital::OutputPin is not satisfied
--> examples/lora_spi_send.rs:626:19
|
626 | let lora = Sx127x::spi(
| ^^^^^^^^^^^ the trait embedded_hal::digital::OutputPin is not implemented for stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>
|
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::delay::Delay: embedded_hal::blocking::delay::DelayMs<u32> is not satisfied
--> examples/lora_spi_send.rs:632:10
|
632 | delay, //Delay
| ^^^^^ the trait embedded_hal::blocking::delay::DelayMs<u32> is not implemented for stm32f4xx_hal::delay::Delay
|
help: trait impl with same name found
--> /home/paul/.cargo/git/checkouts/stm32f4xx-hal-fe8350cc04cacf3f/4b04112/src/delay.rs:30:1
|
30 | / impl DelayMs for Delay {
31 | | fn delay_ms(&mut self, ms: u32) {
32 | | self.delay_us(ms * 1_000);
33 | | }
34 | | }
| |_^
= note: perhaps two different versions of crate embedded_hal are being used?
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0277]: the trait bound stm32f4xx_hal::delay::Delay: embedded_hal::blocking::delay::DelayUs<u32> is not satisfied
--> examples/lora_spi_send.rs:632:10
|
632 | delay, //Delay
| ^^^^^ the trait embedded_hal::blocking::delay::DelayUs<u32> is not implemented for stm32f4xx_hal::delay::Delay
|
help: trait impl with same name found
--> /home/paul/.cargo/git/checkouts/stm32f4xx-hal-fe8350cc04cacf3f/4b04112/src/delay.rs:82:1
|
82 | / impl DelayUs for Delay {
83 | | fn delay_us(&mut self, us: u8) {
84 | | self.delay_us(u32(us))
85 | | }
86 | | }
| |_^
= note: perhaps two different versions of crate embedded_hal are being used?
= note: required by radio_sx127x::Sx127x::<driver_pal::wrapper::Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError>, SpiError, PinError, DelayError>::spi

error[E0599]: no method named start_transmit found for struct radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _> in the current scope
--> examples/lora_spi_send.rs:679:13
|
679 | lora.start_transmit(message).unwrap(); // should handle error
| ^^^^^^^^^^^^^^ method not found in radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _>
|
::: /home/paul/.cargo/registry/src/github.com-1ecc6299db9ec823/driver-pal-0.8.0-alpha.0/src/wrapper.rs:12:1
|
12 | pub struct Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError> {
| -------------------------------------------------------------------------------------------------- doesn't satisfy _: radio_sx127x::base::Base<_, _, _>
|
::: /home/paul/githubClones/rust-radio-sx127x/src/lib.rs:56:1
|
56 | pub struct Sx127x<Base, CommsError, PinError, DelayError> {
| --------------------------------------------------------- doesn't satisfy _: radio::Transmit
|
= note: the method start_transmit exists but the following trait bounds were not satisfied:
driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>: radio_sx127x::base::Base<_, _, _>
which is required by radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _>: radio::Transmit

error[E0599]: no method named check_transmit found for struct radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _> in the current scope
--> examples/lora_spi_send.rs:681:19
|
681 | match lora.check_transmit() {
| ^^^^^^^^^^^^^^ method not found in radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _>
|
::: /home/paul/.cargo/registry/src/github.com-1ecc6299db9ec823/driver-pal-0.8.0-alpha.0/src/wrapper.rs:12:1
|
12 | pub struct Wrapper<Spi, SpiError, CsPin, BusyPin, ReadyPin, ResetPin, PinError, Delay, DelayError> {
| -------------------------------------------------------------------------------------------------- doesn't satisfy _: radio_sx127x::base::Base<_, _, _>
|
::: /home/paul/githubClones/rust-radio-sx127x/src/lib.rs:56:1
|
56 | pub struct Sx127x<Base, CommsError, PinError, DelayError> {
| --------------------------------------------------------- doesn't satisfy _: radio::Transmit
|
= note: the method check_transmit exists but the following trait bounds were not satisfied:
driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>: radio_sx127x::base::Base<_, _, _>
which is required by radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _>: radio::Transmit

error[E0599]: no method named delay_ms found for struct radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _> in the current scope
--> examples/lora_spi_send.rs:688:13
|
688 | lora.delay_ms(5000u32);
| ^^^^^^^^ method not found in radio_sx127x::Sx127x<driver_pal::wrapper::Wrapper<stm32f4xx_hal::spi::Spi<stm32f4::stm32f411::SPI1, (stm32f4xx_hal::gpio::gpioa::PA5<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA6<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>, stm32f4xx_hal::gpio::gpioa::PA7<stm32f4xx_hal::gpio::Alternate<stm32f4xx_hal::gpio::AF5>>)>, _, stm32f4xx_hal::gpio::gpioa::PA1<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, stm32f4xx_hal::gpio::gpiob::PB8<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpiob::PB9<stm32f4xx_hal::gpio::Input<stm32f4xx_hal::gpio::Floating>>, stm32f4xx_hal::gpio::gpioa::PA0<stm32f4xx_hal::gpio::Output<stm32f4xx_hal::gpio::PushPull>>, _, stm32f4xx_hal::delay::Delay, _>, _, _, _>

warning: unused import: Transmit
--> examples/lora_spi_send.rs:65:13
|
65 | use radio::{Transmit}; // trait needs to be in scope to find methods start_transmit and check_transmit.
| ^^^^^^^^

error: aborting due to 12 previous errors; 4 warnings emitted

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try rustc --explain E0277.
error: could not compile radio-sx127x.

</details>

TX_DONE interrupt not firing.

I can't seem to get the TX_DONE interrupt to fire, however the RX_DONE interrupt works fine.

My code currently operates like so:

  1. Send a packet
  2. TX_DONE interrupt should fire, but it doesn't, I currently have to poll.
  3. Receive a packet
  4. RX_DONE interrupt fires, no polling needed.
  5. I can check the bit flags and see that both TX_DONE and RX_DONE are set, I've messed around with the IRQ bit flags but haven't had success.

I'm using RTIC and embedded-hal/atsamd-hal. The code is here

no_std newbie questions

I realize this is work in progress, so maybe you are not ready for newbies like me. Don't hesitate to tell me I need to be patient, but if your direction is not consistent with what I am trying to do then it would be nice to know that I should be looking elsewhere.

I am trying to build the LoRa sending side of a sensor to base station connection. I have both sides working on R Pi with python, but would like to run at least the sending side with rust on no_std stm32xxx. So I do have a working receiving side to test against. I am currently using an RFM95 sx1276 style radio.

  • Should this crate work with no_std (I hope so)? There seems to be some indirect dependency on ansi_term, lazy_static and termcolor which I think need std so I get an error about can't find crate std. I am using master branch.

  • With no luck finding an example, I've looked at the integration test, but it uses std. Is there
    another example I should be looking at?

  • Should the crate already work if I only have one radio, so do not have the problem described in issue #10 ?

  • I think the frequency is a u32 indicating hertz but somewhere I saw something that that seemed like it might be megahertz. Megahertz would mean only some channels can be used (867.0, 868.0, 915.0). Am I correct that the frequency in hertz?

  • The integration test loads a configuration from a file. Thinking no_std I would like to just specify
    the configuration in the code, but I cannot figure out if I should be setting this with radio_sx127x::spi(),
    Sx127x::new(), or with lora_configure() after I have an object. I am confused about what is intended to be the user API and what are internal utilities. A quick reaction to my attempt (code below) would be much appreciated.

  • I am also very unsure about the hardware wiring, so I have added comments in the code. From #7 I see that "busy" should DIO0, I guess on a gpio pin configured as push_pull_output? I am also unsure about the pin for "ready". Should it be another of the DIOx pins?

Thanks very much for your work on this crate.

#![no_std]
#![no_main]

#[cfg(debug_assertions)]
extern crate panic_semihosting;

#[cfg(not(debug_assertions))]
extern crate panic_halt;

// use nb::block;
use cortex_m_rt::entry;
use cortex_m_semihosting::*;
//use asm_delay::{ AsmDelay, bitrate, };

extern crate radio_sx127x;
use radio_sx127x::{prelude::*,
                   LoRaConfig,
                   LoRaChannel,
		   };

extern crate radio;
use radio::{Receive, Transmit};

use stm32f1xx_hal::{prelude::*,   
                    pac::Peripherals, 
                    spi::{Spi, Spi1NoRemap},
                    delay::Delay,
                    gpio::{gpioa::{PA5, PA6, PA7}, Alternate, Input, Floating,  
                           gpioa::{PA0, PA1}, Output, PushPull},
                    device::SPI1,
                    }; 


const FREQUENCY: u32 = 915_000_000;  // frequency in hertz


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

    // base setup  ( using stm32f1xx_hal )
    
    let cp = cortex_m::Peripherals::take().unwrap();
    let p  = Peripherals::take().unwrap();
    
    let mut rcc   = p.RCC.constrain();
    let clocks = rcc.cfgr.sysclk(64.mhz()).pclk1(32.mhz()).freeze(&mut p.FLASH.constrain().acr);
    
    let mut afio = p.AFIO.constrain(&mut rcc.apb2);
    let mut gpioa = p.GPIOA.split(&mut rcc.apb2);
    let mut gpiob = p.GPIOB.split(&mut rcc.apb2);

    // stm32f1xx_hal spi setup
    let spi = Spi::spi1(
    	p.SPI1,
    	(gpioa.pa5.into_alternate_push_pull(&mut gpioa.crl),  //   sck   on PA5
    	 gpioa.pa6.into_floating_input(&mut gpioa.crl),       //   miso  on PA6
    	 gpioa.pa7.into_alternate_push_pull(&mut gpioa.crl)   //   mosi  on PA7
    	 ),
    	&mut afio.mapr,
    	sx127x_lora::MODE, 
    	8.mhz(),	
    	clocks, 
    	&mut rcc.apb2,
    	);
       
    let mut delay = Delay::new(cp.SYST, clocks);
 
    
    /// Create lora radio instance 
    
    let config = LoRaConfig {
    	preamble_len: 0x8,
    	symbol_timeout: 0x64,
    	payload_len: PayloadLength::Variable,
    	payload_crc: PayloadCrc::Enabled,
    	frequency_hop: FrequencyHopping::Disabled,
    	invert_iq: false,
    }

    //   other settings?
    //    lora.set_mode(sx127x_lora::RadioMode::Stdby).unwrap();
    //    set_tx_power(level, output_pin) level >17 => PA_BOOST. 
    //    lora.set_tx_power(17,1).unwrap();  
    //    lora.set_tx_power(15,1).unwrap();  
    
    let ch = LoRaChannel {
    		freq: FREQUENCY as u32, 	   // frequency in hertz
    		bw: Bandwidth::Bw125kHz,
    		sf: SpreadingFactor::Sf7,
    		cr: CodingRate::Cr4_8,  	  
    		}
    
    //baud = 1000000 is this needed for spi or just USART
    
          (gpiob.pb8.into_alternate_open_drain(&mut gpiob.crh),   // scl on PB8
           gpiob.pb9.into_alternate_open_drain(&mut gpiob.crh)),  // sda on PB9

    let mut lora = radio_sx127x::spi(
    	    spi,					       //Spi,
    	    gpioa.pa1.into_push_pull_output(&mut gpioa.crl),   //CsPin,   on PA1
    	    gpiob.pb8.into_push_pull_output(&mut gpiob.crh),   //BusyPin, D00 on PB8
    	    gpiob.pb9.into_push_pull_output(&mut gpiob.crh)),  ///ReadyPin, D01 ? on PB9
    	    gpioa.pa0.into_push_pull_output(&mut gpioa.crl),   //ResetPin, on PA0
    	    delay,					       //Delay,
    	    &config,					       //&Config,
    	    ).unwrap();      // should handle error
    
    //DIO0  triggers RxDone/TxDone status.
    //DIO1  triggers RxTimeout and other errors status.
    //D02, D03 ?
    
    // or ?
    //   pub fn new(hal: Base, config: &Config) -> Result<Self, Error<CommsError, PinError>> {
    //let mut lora = Sx127x::new( w2, &config ).unwrap();   // should handle error
    
    // or ?
    // lora.lora_configure( config, channel: &LoRaChannel, ).unwrap()
    
    
    
    // print out configuration (for debugging)
    
    let v = lora.lora_get_config():
    hprintln!("configuration {}", v).unwrap()
    
    hprintln!("chammel	  {}", lora.get_chammel()).unwrap();

    //hprintln!("mode		  {}", lora.get_mode()).unwrap();
    //hprintln!("mode		  {}", lora.read_register(Register::RegOpMode.addr())).unwrap();
    //hprintln!("bandwidth	  {:?}", lora.get_signal_bandwidth()).unwrap();
    //hprintln!("coding_rate	  {:?}",  lora.get_coding_rate_4()).unwrap();
    //hprintln!("spreading_factor {:?}",  lora.get_spreading_factor()).unwrap();
    //hprintln!("spreading_factor {:?}",  
    //hprintln!("invert_iq	  {:?}",  lora.get_invert_iq()).unwrap();
    //hprintln!("tx_power	  {:?}",  lora.get_tx_power()).unwrap();
    
    
    
    // transmit something
      
    //let buffer = &[0xaa, 0xbb, 0xcc];
    
    let message = "Hello, LoRa!";
    
    let mut buffer = [0;255];
    for (i,c) in message.chars().enumerate() {
    	buffer[i] = c as u8;
    	}
    
    lora.start_transmit(buffer).unwrap();    // should handle error
    
    if lora.check_transmit().unwrap() {
    		hprintln!("TX complete");
    		};
    
    
    
    loop {};
}

impl Transmit

While learning Rust I have been working through some examples that I am trying to do in a way that they will work with several stm32*xx_hal's. (The examples using rust-radio-sx127x are the lora_spi_* ones in the second table in my scoreboard at https://pdgilbert.github.io/eg_stm_hal/ .)

Following a suggestion of https://github.com/TheZoq2 in issue stm32-rs/stm32f1xx-hal#234 (comment) I am using setup() functions for hal specific code. These setup() functions return objects that can be used in application code that is common for all setups. One of the most difficult parts of this is determining the return value for the setup functions, which requires details the compiler looks after if the code is not separated into a function. For example, the signature for the lora_spi_send example needs

    fn setup() ->  Sx127x<Wrapper<Spi<SPI1, (PA5<Alternate<AF5>>,    PA6<Alternate<AF5>>,   PA7<Alternate<AF5>>)>,  Error, 
                   PA1<Output<PushPull>>,  PB8<Input<Floating>>,  PB9<Input<Floating>>,  PA0<Output<PushPull>>, 
                   core::convert::Infallible,  Delay>,  Error, core::convert::Infallible> {

(The complete example code is at https://github.com/pdgilbert/eg_stm_hal/blob/master/examples/lora_spi_send.rs )

When traits are available I think I should be able to replace the function signature with

 fn setup() ->  impl Transmit {

but when I do that I get errors about trait bounds were not satisfied:


error[E0599]: no method named `unwrap` found for enum `core::result::Result<(), <impl radio::Transmit as radio::Transmit>::Error>` in the current scope
   --> examples/lora_spi_send.rs:674:37
    |
674 |        lora.start_transmit(message).unwrap();    // should handle error
    |                                     ^^^^^^ method not found in `core::result::Result<(), <impl radio::Transmit as radio::Transmit>::Error>`
    |
    = note: the method `unwrap` exists but the following trait bounds were not satisfied:
            `<impl radio::Transmit as radio::Transmit>::Error: core::fmt::Debug`

error[E0599]: no method named `delay_ms` found for opaque type `impl radio::Transmit` in the current scope
   --> examples/lora_spi_send.rs:683:13
    |
683 |        lora.delay_ms(5000u32);
    |             ^^^^^^^^ method not found in `impl radio::Transmit`

error: aborting due to 2 previous errors; 2 warnings emitted

Am I doing something wrong?

lora_check_receive restart argument

Following code in the tests/integration.rs file I have my lora_sp_receive example working on an stm32f411 but I am confused by the restart option, especial a true setting, and not sure if I correctly understand the comment (src/lora.rs line 336)

/// This returns true if a boolean indicating whether a packet has been received.
/// The restart option specifies whether transient timeout or CRC errors should be
/// internally handled (returning Ok(false)) or passed back to the caller as errors.

Does that mean that

  • lora_check_receive(false) passes the check result back to user code and returns Ok(true) if a packet has been received and Ok(false) if nothing has been received or if there has been a timeout or CRC error.

  • lora_check_receive(true) always returns Ok(false). It handles timeouts and CRC errors without passing back to user code. It waits until something is received? So blocks?

Why is the argument called "restart option"?

Which restart option do you suggest in what situations?

For reference, the example code is at https://github.com/pdgilbert/eg_stm_hal/blob/master/examples/lora_spi_receive.rs and currently the main part is

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


    let mut lora =  setup();         //delay is available in lora
    
    lora.start_receive().unwrap();   // should handle error

    let mut buff = [0u8; 1024];
    let mut n: usize ;
    let mut info = PacketInfo::default();


    loop {

       let poll = lora.check_receive(false);    

       match poll {
            Ok(v)  if v  =>  {n = lora.get_received(&mut info, &mut buff).unwrap();
                              hprintln!("RX complete ({:?}, length: {})", info, n).unwrap();
                              //hprintln!("{:?}", &buff[..n]).unwrap();
                              hprintln!("{}", to_str(&buff[..n])).unwrap();
                              },

            Ok(_v)       =>  hprint!(".").unwrap(),           // print . if nothing received
            
	    Err(err)     =>  hprintln!("poll error {:?} ", err).unwrap(),
            };

       lora.delay_ms(100u32);
       };

}

`sx127x-util gfsk tx` hangs indefinitely

appears to be entering TX state and asserting TX_READY and FIFO_LEVEL, but not actually transmitting...

./sx127x-util --log-level debug gfsk tx --data "abcd"
17:38:14 [DEBUG] sx127x_util: Connecting to SPI device
17:38:14 [DEBUG] sx127x_util: Configuring I/O pins
17:38:14 [DEBUG] sx127x_util: Creating radio instance
17:38:14 [DEBUG] sx127x_util: Executing command
17:38:14 [DEBUG] radio_sx127x::fsk: Configuring FSK/OOK mode
17:38:14 [DEBUG] radio_sx127x: Updated BOOST PA_CONFIG for: 10 dBm to: 10000100
17:38:14 [DEBUG] radio_sx127x: Updated BOOST PA_CONFIG for: 13 dBm to: 10000100
17:38:14 [DEBUG] radio_sx127x::fsk: Starting send (data: [97, 98, 99, 100])
17:38:14 [DEBUG] radio_sx127x: Set state to: Standby
17:38:14 [DEBUG] radio_sx127x::fsk: clearing interrupts (irq1: MODE_READY irq2: FIFO_EMPTY)
17:38:14 [DEBUG] radio_sx127x: Set state to: Tx
17:38:14 [DEBUG] radio_sx127x::fsk: clearing interrupts (irq1: MODE_READY | TX_READY irq2: FIFO_EMPTY)
17:38:14 [DEBUG] radio_sx127x::fsk: Check transmit IRQ1: MODE_READY | TX_READY IRQ2: FIFO_LEVEL
17:38:14 [DEBUG] radio_sx127x::fsk: Check transmit IRQ1: MODE_READY | TX_READY IRQ2: FIFO_LEVEL
17:38:14 [DEBUG] radio_sx127x::fsk: Check transmit IRQ1: MODE_READY | TX_READY IRQ2: FIFO_LEVEL

RFM95 enable frontend TX / RX support

I have an RFM95 like radio working in my testing. It uses 9 pins: gnd, vcc, nss(cspin), reset, DIO0, DIO1, and spi(sck, miso, mosi). I can also successfully run my tests using an Ebyte E19-915M30S described in the manual at http://www.ebyte.com/en/product-view-news.aspx?id=223. (See also the description for a slightly different form factor of the same radio in an Arduino project at https://github.com/beegee-tokyo/SX126x-Arduino/#explanation-for-txco-and-antenna-control)

This radio has two additional pins RXEN and TXEN to "enable the antenna" for rx and tx. (I'm not sure what these do, if it is really just PA boost or not?) These I can hard wire, for transmit vcc to TXEN and gnd to RXEN, and the reverse for receive. This works for my testing, which only does one or the other, but it seems like these should be under software control. Is there something I am missing in rust-radio-sx127x to do this?

sharing spi?

In theory I can put a few devices on the spi bus. However, I think lora consumes spi. Am I correct in thinking there may be a problem, or is this something I can try easily?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.