Move embassy-lora, lora examples to lora-phy repo.
This commit is contained in:
@ -11,10 +11,6 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de
|
||||
embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||
embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" }
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
|
||||
lora-phy = { version = "2" }
|
||||
lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"] }
|
||||
lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"] }
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
|
@ -1,95 +0,0 @@
|
||||
//! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio.
|
||||
//! It demonstrates LoRaWAN join functionality.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait, async_fn_in_trait)]
|
||||
#![allow(stable_features, unknown_lints, async_fn_in_trait)]
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
|
||||
use embassy_lora::LoraTimer;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::rng::{self, Rng};
|
||||
use embassy_stm32::spi::Spi;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::{bind_interrupts, peripherals};
|
||||
use embassy_time::Delay;
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use lorawan::default_crypto::DefaultFactory as Crypto;
|
||||
use lorawan_device::async_device::lora_radio::LoRaRadio;
|
||||
use lorawan_device::async_device::{region, Device, JoinMode};
|
||||
use lorawan_device::{AppEui, AppKey, DevEui};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
SUBGHZ_RADIO => InterruptHandler;
|
||||
RNG => rng::InterruptHandler<peripherals::RNG>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
{
|
||||
use embassy_stm32::rcc::*;
|
||||
config.rcc.hse = Some(Hse {
|
||||
freq: Hertz(32_000_000),
|
||||
mode: HseMode::Bypass,
|
||||
prescaler: HsePrescaler::DIV1,
|
||||
});
|
||||
config.rcc.mux = ClockSrc::PLL1_R;
|
||||
config.rcc.pll = Some(Pll {
|
||||
source: PllSource::HSE,
|
||||
prediv: PllPreDiv::DIV2,
|
||||
mul: PllMul::MUL6,
|
||||
divp: None,
|
||||
divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG
|
||||
divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2)
|
||||
});
|
||||
}
|
||||
let p = embassy_stm32::init(config);
|
||||
|
||||
let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
|
||||
|
||||
// Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx
|
||||
let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High);
|
||||
let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
|
||||
let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap();
|
||||
|
||||
let lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), true, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
let radio = LoRaRadio::new(lora);
|
||||
let region: region::Configuration = region::Configuration::new(LORAWAN_REGION);
|
||||
let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs));
|
||||
|
||||
defmt::info!("Joining LoRaWAN network");
|
||||
|
||||
// TODO: Adjust the EUI and Keys according to your network credentials
|
||||
match device
|
||||
.join(&JoinMode::OTAA {
|
||||
deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(()) => defmt::info!("LoRaWAN network joined"),
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
//! This example runs on the STM32WL board, which has a builtin Semtech Sx1262 radio.
|
||||
//! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait, async_fn_in_trait)]
|
||||
#![allow(stable_features, unknown_lints, async_fn_in_trait)]
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::spi::Spi;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_time::{Delay, Timer};
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
SUBGHZ_RADIO => InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
{
|
||||
use embassy_stm32::rcc::*;
|
||||
config.rcc.hse = Some(Hse {
|
||||
freq: Hertz(32_000_000),
|
||||
mode: HseMode::Bypass,
|
||||
prescaler: HsePrescaler::DIV1,
|
||||
});
|
||||
config.rcc.mux = ClockSrc::PLL1_R;
|
||||
config.rcc.pll = Some(Pll {
|
||||
source: PllSource::HSE,
|
||||
prediv: PllPreDiv::DIV2,
|
||||
mul: PllMul::MUL6,
|
||||
divp: None,
|
||||
divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG
|
||||
divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2)
|
||||
});
|
||||
}
|
||||
let p = embassy_stm32::init(config);
|
||||
|
||||
let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
|
||||
|
||||
// Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx
|
||||
let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High);
|
||||
let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
|
||||
let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap();
|
||||
|
||||
let mut lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut debug_indicator = Output::new(p.PB9, Level::Low, Speed::Low);
|
||||
let mut start_indicator = Output::new(p.PB15, Level::Low, Speed::Low);
|
||||
|
||||
start_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
start_indicator.set_low();
|
||||
|
||||
let mut receiving_buffer = [00u8; 100];
|
||||
|
||||
let mdltn_params = {
|
||||
match lora.create_modulation_params(
|
||||
SpreadingFactor::_10,
|
||||
Bandwidth::_250KHz,
|
||||
CodingRate::_4_8,
|
||||
LORA_FREQUENCY_IN_HZ,
|
||||
) {
|
||||
Ok(mp) => mp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let rx_pkt_params = {
|
||||
match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) {
|
||||
Ok(pp) => pp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match lora
|
||||
.prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false)
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
loop {
|
||||
receiving_buffer = [00u8; 100];
|
||||
match lora.rx(&rx_pkt_params, &mut receiving_buffer).await {
|
||||
Ok((received_len, _rx_pkt_status)) => {
|
||||
if (received_len == 3)
|
||||
&& (receiving_buffer[0] == 0x01u8)
|
||||
&& (receiving_buffer[1] == 0x02u8)
|
||||
&& (receiving_buffer[2] == 0x03u8)
|
||||
{
|
||||
info!("rx successful");
|
||||
debug_indicator.set_high();
|
||||
Timer::after_secs(5).await;
|
||||
debug_indicator.set_low();
|
||||
} else {
|
||||
info!("rx unknown packet");
|
||||
}
|
||||
}
|
||||
Err(err) => info!("rx unsuccessful = {}", err),
|
||||
}
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
//! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio.
|
||||
//! It demonstrates LORA P2P send functionality.
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![macro_use]
|
||||
#![feature(type_alias_impl_trait, async_fn_in_trait)]
|
||||
#![allow(stable_features, unknown_lints, async_fn_in_trait)]
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant};
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use embassy_stm32::gpio::{Level, Output, Pin, Speed};
|
||||
use embassy_stm32::spi::Spi;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_time::Delay;
|
||||
use lora_phy::mod_params::*;
|
||||
use lora_phy::sx1261_2::SX1261_2;
|
||||
use lora_phy::LoRa;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
||||
|
||||
bind_interrupts!(struct Irqs{
|
||||
SUBGHZ_RADIO => InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let mut config = embassy_stm32::Config::default();
|
||||
{
|
||||
use embassy_stm32::rcc::*;
|
||||
config.rcc.hse = Some(Hse {
|
||||
freq: Hertz(32_000_000),
|
||||
mode: HseMode::Bypass,
|
||||
prescaler: HsePrescaler::DIV1,
|
||||
});
|
||||
config.rcc.mux = ClockSrc::PLL1_R;
|
||||
config.rcc.pll = Some(Pll {
|
||||
source: PllSource::HSE,
|
||||
prediv: PllPreDiv::DIV2,
|
||||
mul: PllMul::MUL6,
|
||||
divp: None,
|
||||
divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG
|
||||
divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2)
|
||||
});
|
||||
}
|
||||
let p = embassy_stm32::init(config);
|
||||
|
||||
let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2);
|
||||
|
||||
// Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx
|
||||
let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High);
|
||||
let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
|
||||
let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High);
|
||||
let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap();
|
||||
|
||||
let mut lora = {
|
||||
match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await {
|
||||
Ok(l) => l,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mdltn_params = {
|
||||
match lora.create_modulation_params(
|
||||
SpreadingFactor::_10,
|
||||
Bandwidth::_250KHz,
|
||||
CodingRate::_4_8,
|
||||
LORA_FREQUENCY_IN_HZ,
|
||||
) {
|
||||
Ok(mp) => mp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let mut tx_pkt_params = {
|
||||
match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) {
|
||||
Ok(pp) => pp,
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
match lora.prepare_for_tx(&mdltn_params, 20, false).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
let buffer = [0x01u8, 0x02u8, 0x03u8];
|
||||
match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await {
|
||||
Ok(()) => {
|
||||
info!("TX DONE");
|
||||
}
|
||||
Err(err) => {
|
||||
info!("Radio error = {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
match lora.sleep(false).await {
|
||||
Ok(()) => info!("Sleep successful"),
|
||||
Err(err) => info!("Sleep unsuccessful = {}", err),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user