Merge #839
839: Misc LoRaWAN improvements r=lulf a=timokroeger Trying too get `embassy-lora` running on a [LoRa-E5 Dev Board](https://wiki.seeedstudio.com/LoRa_E5_Dev_Board/). I can see the join message arriving in the The Things Network console but the device does not receive the accept message yet. Opening this PR anyway because I think there are some nice things to decouple the lora crate from the nucleo board. `@lulf` Could you test if this PR breaks your LoRa setup? Marking as draft for the time being. Co-authored-by: Timo Kröger <timokroeger93@gmail.com> Co-authored-by: Ulf Lilleengen <lulf@redhat.com>
This commit is contained in:
@ -14,7 +14,7 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
|
||||
|
||||
lorawan-device = { version = "0.7.1", default-features = false, features = ["async"], optional = true }
|
||||
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"], optional = true }
|
||||
lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"], optional = true }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) {
|
||||
let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap();
|
||||
|
||||
let region = region::EU868::default().into();
|
||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG));
|
||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG));
|
||||
|
||||
defmt::info!("Joining LoRaWAN network");
|
||||
|
||||
|
@ -10,7 +10,7 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
|
||||
|
||||
lorawan-device = { version = "0.7.1", default-features = false, features = ["async"] }
|
||||
lorawan-device = { version = "0.8.0", default-features = false, features = ["async"] }
|
||||
lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"] }
|
||||
|
||||
defmt = "0.3"
|
||||
|
@ -9,7 +9,7 @@ use embassy_executor::Spawner;
|
||||
use embassy_lora::stm32wl::*;
|
||||
use embassy_lora::LoraTimer;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed};
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::subghz::*;
|
||||
use embassy_stm32::{interrupt, pac};
|
||||
@ -17,6 +17,32 @@ use lorawan::default_crypto::DefaultFactory as Crypto;
|
||||
use lorawan_device::async_device::{region, Device, JoinMode};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
struct RadioSwitch<'a> {
|
||||
ctrl1: Output<'a, AnyPin>,
|
||||
ctrl2: Output<'a, AnyPin>,
|
||||
ctrl3: Output<'a, AnyPin>,
|
||||
}
|
||||
|
||||
impl<'a> RadioSwitch<'a> {
|
||||
fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self {
|
||||
Self { ctrl1, ctrl2, ctrl3 }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> embassy_lora::stm32wl::RadioSwitch for RadioSwitch<'a> {
|
||||
fn set_rx(&mut self) {
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_low();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
|
||||
fn set_tx(&mut self) {
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_high();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
@ -31,18 +57,19 @@ async fn main(_spawner: Spawner) {
|
||||
let ctrl3 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let rfs = RadioSwitch::new(ctrl1, ctrl2, ctrl3);
|
||||
|
||||
let radio = SubGhz::new(p.SUBGHZSPI, p.PA5, p.PA7, p.PA6, NoDma, NoDma);
|
||||
|
||||
let radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma);
|
||||
let irq = interrupt::take!(SUBGHZ_RADIO);
|
||||
static mut RADIO_STATE: SubGhzState<'static> = SubGhzState::new();
|
||||
let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) };
|
||||
|
||||
let mut radio_config = SubGhzRadioConfig::default();
|
||||
radio_config.calibrate_image = CalibrateImage::ISM_863_870;
|
||||
let radio = SubGhzRadio::new(radio, rfs, irq, radio_config).unwrap();
|
||||
|
||||
let mut region: region::Configuration = region::EU868::default().into();
|
||||
|
||||
// NOTE: This is specific for TTN, as they have a special RX1 delay
|
||||
region.set_receive_delay1(5000);
|
||||
|
||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG));
|
||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG));
|
||||
|
||||
// Depending on network, this might be part of JOIN
|
||||
device.set_datarate(region::DR::_0); // SF12
|
||||
|
@ -72,7 +72,7 @@ async fn main(_spawner: Spawner) {
|
||||
unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable();
|
||||
});
|
||||
|
||||
let mut radio = SubGhz::new(p.SUBGHZSPI, p.PA5, p.PA7, p.PA6, NoDma, NoDma);
|
||||
let mut radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma);
|
||||
|
||||
defmt::info!("Radio ready for use");
|
||||
|
||||
|
Reference in New Issue
Block a user