Move embassy-lora, lora examples to lora-phy repo.
This commit is contained in:
parent
b4bc9ac028
commit
1b9925e3da
@ -1,31 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "embassy-lora"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
|
|
||||||
[package.metadata.embassy_docs]
|
|
||||||
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-lora-v$VERSION/embassy-lora/src/"
|
|
||||||
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-lora/src/"
|
|
||||||
features = ["stm32wl", "embassy-stm32?/stm32wl55jc-cm4", "embassy-stm32?/unstable-pac", "time", "defmt"]
|
|
||||||
target = "thumbv7em-none-eabi"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
stm32wl = ["dep:embassy-stm32"]
|
|
||||||
time = ["embassy-time", "lorawan-device"]
|
|
||||||
defmt = ["dep:defmt", "lorawan-device/defmt"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
|
|
||||||
defmt = { version = "0.3", optional = true }
|
|
||||||
log = { version = "0.4.14", optional = true }
|
|
||||||
|
|
||||||
embassy-time = { version = "0.1.5", path = "../embassy-time", optional = true }
|
|
||||||
embassy-sync = { version = "0.4.0", path = "../embassy-sync" }
|
|
||||||
embassy-stm32 = { version = "0.1.0", path = "../embassy-stm32", default-features = false, optional = true }
|
|
||||||
embedded-hal-async = { version = "=1.0.0-rc.1" }
|
|
||||||
embedded-hal = { version = "0.2", features = ["unproven"] }
|
|
||||||
|
|
||||||
futures = { version = "0.3.17", default-features = false, features = [ "async-await" ] }
|
|
||||||
lora-phy = { version = "2" }
|
|
||||||
lorawan-device = { version = "0.11.0", default-features = false, features = ["async"], optional = true }
|
|
@ -1,258 +0,0 @@
|
|||||||
#![macro_use]
|
|
||||||
#![allow(unused_macros)]
|
|
||||||
|
|
||||||
use core::fmt::{Debug, Display, LowerHex};
|
|
||||||
|
|
||||||
#[cfg(all(feature = "defmt", feature = "log"))]
|
|
||||||
compile_error!("You may not enable both `defmt` and `log` features.");
|
|
||||||
|
|
||||||
macro_rules! assert {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::assert!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::assert!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_eq {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::assert_eq!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::assert_eq!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! assert_ne {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::assert_ne!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::assert_ne!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug_assert {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::debug_assert!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug_assert!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug_assert_eq {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::debug_assert_eq!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug_assert_eq!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug_assert_ne {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::debug_assert_ne!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug_assert_ne!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! todo {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::todo!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::todo!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
macro_rules! unreachable {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
::core::unreachable!($($x)*)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
macro_rules! unreachable {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
::defmt::unreachable!($($x)*)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! panic {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
{
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
::core::panic!($($x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::panic!($($x)*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! trace {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::trace!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::trace!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! debug {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::debug!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::debug!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! info {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::info!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::info!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! warn {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::warn!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::warn!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! error {
|
|
||||||
($s:literal $(, $x:expr)* $(,)?) => {
|
|
||||||
{
|
|
||||||
#[cfg(feature = "log")]
|
|
||||||
::log::error!($s $(, $x)*);
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
::defmt::error!($s $(, $x)*);
|
|
||||||
#[cfg(not(any(feature = "log", feature="defmt")))]
|
|
||||||
let _ = ($( & $x ),*);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
macro_rules! unwrap {
|
|
||||||
($($x:tt)*) => {
|
|
||||||
::defmt::unwrap!($($x)*)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(feature = "defmt"))]
|
|
||||||
macro_rules! unwrap {
|
|
||||||
($arg:expr) => {
|
|
||||||
match $crate::fmt::Try::into_result($arg) {
|
|
||||||
::core::result::Result::Ok(t) => t,
|
|
||||||
::core::result::Result::Err(e) => {
|
|
||||||
::core::panic!("unwrap of `{}` failed: {:?}", ::core::stringify!($arg), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
($arg:expr, $($msg:expr),+ $(,)? ) => {
|
|
||||||
match $crate::fmt::Try::into_result($arg) {
|
|
||||||
::core::result::Result::Ok(t) => t,
|
|
||||||
::core::result::Result::Err(e) => {
|
|
||||||
::core::panic!("unwrap of `{}` failed: {}: {:?}", ::core::stringify!($arg), ::core::format_args!($($msg,)*), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
|
||||||
pub struct NoneError;
|
|
||||||
|
|
||||||
pub trait Try {
|
|
||||||
type Ok;
|
|
||||||
type Error;
|
|
||||||
fn into_result(self) -> Result<Self::Ok, Self::Error>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Try for Option<T> {
|
|
||||||
type Ok = T;
|
|
||||||
type Error = NoneError;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_result(self) -> Result<T, NoneError> {
|
|
||||||
self.ok_or(NoneError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> Try for Result<T, E> {
|
|
||||||
type Ok = T;
|
|
||||||
type Error = E;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn into_result(self) -> Self {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub(crate) struct Bytes<'a>(pub &'a [u8]);
|
|
||||||
|
|
||||||
impl<'a> Debug for Bytes<'a> {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
write!(f, "{:#02x?}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Display for Bytes<'a> {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
write!(f, "{:#02x?}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> LowerHex for Bytes<'a> {
|
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
|
||||||
write!(f, "{:#02x?}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "defmt")]
|
|
||||||
impl<'a> defmt::Format for Bytes<'a> {
|
|
||||||
fn format(&self, fmt: defmt::Formatter) {
|
|
||||||
defmt::write!(fmt, "{:02x}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,317 +0,0 @@
|
|||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
use embassy_stm32::interrupt;
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
use embassy_stm32::interrupt::InterruptExt;
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
use embassy_stm32::pac;
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
use embassy_sync::signal::Signal;
|
|
||||||
use embedded_hal::digital::v2::OutputPin;
|
|
||||||
use embedded_hal_async::delay::DelayUs;
|
|
||||||
use embedded_hal_async::digital::Wait;
|
|
||||||
use lora_phy::mod_params::RadioError::*;
|
|
||||||
use lora_phy::mod_params::{BoardType, RadioError};
|
|
||||||
use lora_phy::mod_traits::InterfaceVariant;
|
|
||||||
|
|
||||||
/// Interrupt handler.
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
pub struct InterruptHandler {}
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
impl interrupt::typelevel::Handler<interrupt::typelevel::SUBGHZ_RADIO> for InterruptHandler {
|
|
||||||
unsafe fn on_interrupt() {
|
|
||||||
interrupt::SUBGHZ_RADIO.disable();
|
|
||||||
IRQ_SIGNAL.signal(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new();
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
/// Base for the InterfaceVariant implementation for an stm32wl/sx1262 combination
|
|
||||||
pub struct Stm32wlInterfaceVariant<CTRL> {
|
|
||||||
board_type: BoardType,
|
|
||||||
rf_switch_rx: Option<CTRL>,
|
|
||||||
rf_switch_tx: Option<CTRL>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
impl<'a, CTRL> Stm32wlInterfaceVariant<CTRL>
|
|
||||||
where
|
|
||||||
CTRL: OutputPin,
|
|
||||||
{
|
|
||||||
/// Create an InterfaceVariant instance for an stm32wl/sx1262 combination
|
|
||||||
pub fn new(
|
|
||||||
_irq: impl interrupt::typelevel::Binding<interrupt::typelevel::SUBGHZ_RADIO, InterruptHandler>,
|
|
||||||
rf_switch_rx: Option<CTRL>,
|
|
||||||
rf_switch_tx: Option<CTRL>,
|
|
||||||
) -> Result<Self, RadioError> {
|
|
||||||
interrupt::SUBGHZ_RADIO.disable();
|
|
||||||
Ok(Self {
|
|
||||||
board_type: BoardType::Stm32wlSx1262, // updated when associated with a specific LoRa board
|
|
||||||
rf_switch_rx,
|
|
||||||
rf_switch_tx,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32wl")]
|
|
||||||
impl<CTRL> InterfaceVariant for Stm32wlInterfaceVariant<CTRL>
|
|
||||||
where
|
|
||||||
CTRL: OutputPin,
|
|
||||||
{
|
|
||||||
fn set_board_type(&mut self, board_type: BoardType) {
|
|
||||||
self.board_type = board_type;
|
|
||||||
}
|
|
||||||
async fn set_nss_low(&mut self) -> Result<(), RadioError> {
|
|
||||||
pac::PWR.subghzspicr().modify(|w| w.set_nss(false));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn set_nss_high(&mut self) -> Result<(), RadioError> {
|
|
||||||
pac::PWR.subghzspicr().modify(|w| w.set_nss(true));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn reset(&mut self, _delay: &mut impl DelayUs) -> Result<(), RadioError> {
|
|
||||||
pac::RCC.csr().modify(|w| w.set_rfrst(true));
|
|
||||||
pac::RCC.csr().modify(|w| w.set_rfrst(false));
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn wait_on_busy(&mut self) -> Result<(), RadioError> {
|
|
||||||
while pac::PWR.sr2().read().rfbusys() {}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn await_irq(&mut self) -> Result<(), RadioError> {
|
|
||||||
unsafe { interrupt::SUBGHZ_RADIO.enable() };
|
|
||||||
IRQ_SIGNAL.wait().await;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_high().map_err(|_| RfSwitchRx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_high().map_err(|_| RfSwitchTx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fn disable_rf_switch(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchTx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Base for the InterfaceVariant implementation for an stm32l0/sx1276 combination
|
|
||||||
pub struct Stm32l0InterfaceVariant<CTRL, WAIT> {
|
|
||||||
board_type: BoardType,
|
|
||||||
nss: CTRL,
|
|
||||||
reset: CTRL,
|
|
||||||
irq: WAIT,
|
|
||||||
rf_switch_rx: Option<CTRL>,
|
|
||||||
rf_switch_tx: Option<CTRL>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTRL, WAIT> Stm32l0InterfaceVariant<CTRL, WAIT>
|
|
||||||
where
|
|
||||||
CTRL: OutputPin,
|
|
||||||
WAIT: Wait,
|
|
||||||
{
|
|
||||||
/// Create an InterfaceVariant instance for an stm32l0/sx1276 combination
|
|
||||||
pub fn new(
|
|
||||||
nss: CTRL,
|
|
||||||
reset: CTRL,
|
|
||||||
irq: WAIT,
|
|
||||||
rf_switch_rx: Option<CTRL>,
|
|
||||||
rf_switch_tx: Option<CTRL>,
|
|
||||||
) -> Result<Self, RadioError> {
|
|
||||||
Ok(Self {
|
|
||||||
board_type: BoardType::Stm32l0Sx1276, // updated when associated with a specific LoRa board
|
|
||||||
nss,
|
|
||||||
reset,
|
|
||||||
irq,
|
|
||||||
rf_switch_rx,
|
|
||||||
rf_switch_tx,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTRL, WAIT> InterfaceVariant for Stm32l0InterfaceVariant<CTRL, WAIT>
|
|
||||||
where
|
|
||||||
CTRL: OutputPin,
|
|
||||||
WAIT: Wait,
|
|
||||||
{
|
|
||||||
fn set_board_type(&mut self, board_type: BoardType) {
|
|
||||||
self.board_type = board_type;
|
|
||||||
}
|
|
||||||
async fn set_nss_low(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.nss.set_low().map_err(|_| NSS)
|
|
||||||
}
|
|
||||||
async fn set_nss_high(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.nss.set_high().map_err(|_| NSS)
|
|
||||||
}
|
|
||||||
async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> {
|
|
||||||
delay.delay_ms(10).await;
|
|
||||||
self.reset.set_low().map_err(|_| Reset)?;
|
|
||||||
delay.delay_ms(10).await;
|
|
||||||
self.reset.set_high().map_err(|_| Reset)?;
|
|
||||||
delay.delay_ms(10).await;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn wait_on_busy(&mut self) -> Result<(), RadioError> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn await_irq(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.irq.wait_for_high().await.map_err(|_| Irq)
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_high().map_err(|_| RfSwitchRx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_high().map_err(|_| RfSwitchTx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fn disable_rf_switch(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchTx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Base for the InterfaceVariant implementation for a generic Sx126x LoRa board
|
|
||||||
pub struct GenericSx126xInterfaceVariant<CTRL, WAIT> {
|
|
||||||
board_type: BoardType,
|
|
||||||
nss: CTRL,
|
|
||||||
reset: CTRL,
|
|
||||||
dio1: WAIT,
|
|
||||||
busy: WAIT,
|
|
||||||
rf_switch_rx: Option<CTRL>,
|
|
||||||
rf_switch_tx: Option<CTRL>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTRL, WAIT> GenericSx126xInterfaceVariant<CTRL, WAIT>
|
|
||||||
where
|
|
||||||
CTRL: OutputPin,
|
|
||||||
WAIT: Wait,
|
|
||||||
{
|
|
||||||
/// Create an InterfaceVariant instance for an nrf52840/sx1262 combination
|
|
||||||
pub fn new(
|
|
||||||
nss: CTRL,
|
|
||||||
reset: CTRL,
|
|
||||||
dio1: WAIT,
|
|
||||||
busy: WAIT,
|
|
||||||
rf_switch_rx: Option<CTRL>,
|
|
||||||
rf_switch_tx: Option<CTRL>,
|
|
||||||
) -> Result<Self, RadioError> {
|
|
||||||
Ok(Self {
|
|
||||||
board_type: BoardType::Rak4631Sx1262, // updated when associated with a specific LoRa board
|
|
||||||
nss,
|
|
||||||
reset,
|
|
||||||
dio1,
|
|
||||||
busy,
|
|
||||||
rf_switch_rx,
|
|
||||||
rf_switch_tx,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<CTRL, WAIT> InterfaceVariant for GenericSx126xInterfaceVariant<CTRL, WAIT>
|
|
||||||
where
|
|
||||||
CTRL: OutputPin,
|
|
||||||
WAIT: Wait,
|
|
||||||
{
|
|
||||||
fn set_board_type(&mut self, board_type: BoardType) {
|
|
||||||
self.board_type = board_type;
|
|
||||||
}
|
|
||||||
async fn set_nss_low(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.nss.set_low().map_err(|_| NSS)
|
|
||||||
}
|
|
||||||
async fn set_nss_high(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.nss.set_high().map_err(|_| NSS)
|
|
||||||
}
|
|
||||||
async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> {
|
|
||||||
delay.delay_ms(10).await;
|
|
||||||
self.reset.set_low().map_err(|_| Reset)?;
|
|
||||||
delay.delay_ms(20).await;
|
|
||||||
self.reset.set_high().map_err(|_| Reset)?;
|
|
||||||
delay.delay_ms(10).await;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
async fn wait_on_busy(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.busy.wait_for_low().await.map_err(|_| Busy)
|
|
||||||
}
|
|
||||||
async fn await_irq(&mut self) -> Result<(), RadioError> {
|
|
||||||
self.dio1.wait_for_high().await.map_err(|_| DIO1)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchTx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_high().map_err(|_| RfSwitchRx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_high().map_err(|_| RfSwitchTx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fn disable_rf_switch(&mut self) -> Result<(), RadioError> {
|
|
||||||
match &mut self.rf_switch_rx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchRx)?,
|
|
||||||
None => (),
|
|
||||||
};
|
|
||||||
match &mut self.rf_switch_tx {
|
|
||||||
Some(pin) => pin.set_low().map_err(|_| RfSwitchTx),
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
#![feature(async_fn_in_trait, impl_trait_projections)]
|
|
||||||
#![allow(stable_features, unknown_lints, async_fn_in_trait)]
|
|
||||||
//! embassy-lora holds LoRa-specific functionality.
|
|
||||||
|
|
||||||
pub(crate) mod fmt;
|
|
||||||
|
|
||||||
/// interface variants required by the external lora physical layer crate (lora-phy)
|
|
||||||
pub mod iv;
|
|
||||||
|
|
||||||
#[cfg(feature = "time")]
|
|
||||||
use embassy_time::{Duration, Instant, Timer};
|
|
||||||
|
|
||||||
/// A convenience timer to use with the LoRaWAN crate
|
|
||||||
#[cfg(feature = "time")]
|
|
||||||
pub struct LoraTimer {
|
|
||||||
start: Instant,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "time")]
|
|
||||||
impl LoraTimer {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self { start: Instant::now() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "time")]
|
|
||||||
impl lorawan_device::async_device::radio::Timer for LoraTimer {
|
|
||||||
fn reset(&mut self) {
|
|
||||||
self.start = Instant::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn at(&mut self, millis: u64) {
|
|
||||||
Timer::at(self.start + Duration::from_millis(millis)).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn delay_ms(&mut self, millis: u64) {
|
|
||||||
Timer::after_millis(millis).await
|
|
||||||
}
|
|
||||||
}
|
|
@ -21,10 +21,6 @@ nightly = [
|
|||||||
"embedded-io-async",
|
"embedded-io-async",
|
||||||
"embedded-hal-bus/async",
|
"embedded-hal-bus/async",
|
||||||
"embassy-net",
|
"embassy-net",
|
||||||
"embassy-lora",
|
|
||||||
"lora-phy",
|
|
||||||
"lorawan-device",
|
|
||||||
"lorawan",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
@ -37,10 +33,6 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defm
|
|||||||
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true }
|
embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"], optional = true }
|
||||||
embedded-io = { version = "0.6.0", features = ["defmt-03"] }
|
embedded-io = { version = "0.6.0", features = ["defmt-03"] }
|
||||||
embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] }
|
embedded-io-async = { version = "0.6.0", optional = true, features = ["defmt-03"] }
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true }
|
|
||||||
lora-phy = { version = "2", optional = true }
|
|
||||||
lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
|
|
||||||
lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true }
|
|
||||||
embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true }
|
embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"], optional = true }
|
||||||
embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true }
|
embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"], optional = true }
|
||||||
|
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
|
||||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
|
||||||
//! It demonstrates LORA CAD functionality.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
|
||||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
|
||||||
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 {
|
|
||||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_nrf::init(Default::default());
|
|
||||||
let mut spi_config = spim::Config::default();
|
|
||||||
spi_config.frequency = spim::Frequency::M16;
|
|
||||||
|
|
||||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
|
||||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
|
||||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
let iv =
|
|
||||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
|
||||||
Ok(l) => l,
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
|
|
||||||
let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
start_indicator.set_high();
|
|
||||||
Timer::after_secs(5).await;
|
|
||||||
start_indicator.set_low();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match lora.prepare_for_cad(&mdltn_params, true).await {
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match lora.cad().await {
|
|
||||||
Ok(cad_activity_detected) => {
|
|
||||||
if cad_activity_detected {
|
|
||||||
info!("cad successful with activity detected")
|
|
||||||
} else {
|
|
||||||
info!("cad successful without activity detected")
|
|
||||||
}
|
|
||||||
debug_indicator.set_high();
|
|
||||||
Timer::after_secs(5).await;
|
|
||||||
debug_indicator.set_low();
|
|
||||||
}
|
|
||||||
Err(err) => info!("cad unsuccessful = {}", err),
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
|
||||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
|
||||||
//! It demonstrates LoRaWAN join functionality.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_lora::LoraTimer;
|
|
||||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
|
||||||
use embassy_nrf::rng::Rng;
|
|
||||||
use embassy_nrf::{bind_interrupts, peripherals, rng, spim};
|
|
||||||
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 {
|
|
||||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
|
||||||
RNG => rng::InterruptHandler<peripherals::RNG>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_nrf::init(Default::default());
|
|
||||||
let mut spi_config = spim::Config::default();
|
|
||||||
spi_config.frequency = spim::Frequency::M16;
|
|
||||||
|
|
||||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
|
||||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
|
||||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
let iv =
|
|
||||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
|
||||||
|
|
||||||
let lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, 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,119 +0,0 @@
|
|||||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
|
||||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
|
||||||
//! 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)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
|
||||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
|
||||||
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 {
|
|
||||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_nrf::init(Default::default());
|
|
||||||
let mut spi_config = spim::Config::default();
|
|
||||||
spi_config.frequency = spim::Frequency::M16;
|
|
||||||
|
|
||||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
|
||||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
|
||||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
let iv =
|
|
||||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
|
||||||
Ok(l) => l,
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
|
|
||||||
let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
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,127 +0,0 @@
|
|||||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
|
||||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
|
||||||
//! It demonstrates LoRa Rx duty cycle functionality in conjunction with the lora_p2p_send example.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
|
||||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
|
||||||
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 {
|
|
||||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_nrf::init(Default::default());
|
|
||||||
let mut spi_config = spim::Config::default();
|
|
||||||
spi_config.frequency = spim::Frequency::M16;
|
|
||||||
|
|
||||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
|
||||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
|
||||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
let iv =
|
|
||||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, iv), false, Delay).await {
|
|
||||||
Ok(l) => l,
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_indicator = Output::new(p.P1_03, Level::Low, OutputDrive::Standard);
|
|
||||||
let mut start_indicator = Output::new(p.P1_04, Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// See "RM0453 Reference manual STM32WL5x advanced Arm®-based 32-bit MCUs with sub-GHz radio solution" for the best explanation of Rx duty cycle processing.
|
|
||||||
match lora
|
|
||||||
.prepare_for_rx(
|
|
||||||
&mdltn_params,
|
|
||||||
&rx_pkt_params,
|
|
||||||
None,
|
|
||||||
Some(&DutyCycleParams {
|
|
||||||
rx_time: 300_000, // 300_000 units * 15.625 us/unit = 4.69 s
|
|
||||||
sleep_time: 200_000, // 200_000 units * 15.625 us/unit = 3.13 s
|
|
||||||
}),
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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,102 +0,0 @@
|
|||||||
//! This example runs on the RAK4631 WisBlock, which has an nRF52840 MCU and Semtech Sx126x radio.
|
|
||||||
//! Other nrf/sx126x combinations may work with appropriate pin modifications.
|
|
||||||
//! It demonstrates LORA P2P send functionality.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pin as _, Pull};
|
|
||||||
use embassy_nrf::{bind_interrupts, peripherals, spim};
|
|
||||||
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 {
|
|
||||||
SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1 => spim::InterruptHandler<peripherals::TWISPI1>;
|
|
||||||
});
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_nrf::init(Default::default());
|
|
||||||
let mut spi_config = spim::Config::default();
|
|
||||||
spi_config.frequency = spim::Frequency::M16;
|
|
||||||
|
|
||||||
let spim = spim::Spim::new(p.TWISPI1, Irqs, p.P1_11, p.P1_13, p.P1_12, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.P1_10.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let reset = Output::new(p.P1_06.degrade(), Level::High, OutputDrive::Standard);
|
|
||||||
let dio1 = Input::new(p.P1_15.degrade(), Pull::Down);
|
|
||||||
let busy = Input::new(p.P1_14.degrade(), Pull::Down);
|
|
||||||
let rf_switch_rx = Output::new(p.P1_05.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
let rf_switch_tx = Output::new(p.P1_07.degrade(), Level::Low, OutputDrive::Standard);
|
|
||||||
|
|
||||||
let iv =
|
|
||||||
GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, Some(rf_switch_rx), Some(rf_switch_tx)).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::Rak4631Sx1262, spim, 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),
|
|
||||||
}
|
|
||||||
}
|
|
@ -16,10 +16,6 @@ embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defm
|
|||||||
embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] }
|
embassy-net-wiznet = { version = "0.1.0", path = "../../embassy-net-wiznet", features = ["defmt"] }
|
||||||
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
|
||||||
embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" }
|
embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" }
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["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"] }
|
|
||||||
cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] }
|
cyw43 = { path = "../../cyw43", features = ["defmt", "firmware-logs"] }
|
||||||
cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] }
|
cyw43-pio = { path = "../../cyw43-pio", features = ["defmt", "overclock"] }
|
||||||
|
|
||||||
|
@ -1,74 +0,0 @@
|
|||||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
|
||||||
//! It demonstrates LoRaWAN join functionality.
|
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_lora::LoraTimer;
|
|
||||||
use embassy_rp::gpio::{Input, Level, Output, Pin, Pull};
|
|
||||||
use embassy_rp::spi::{Config, Spi};
|
|
||||||
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
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_rp::init(Default::default());
|
|
||||||
|
|
||||||
let miso = p.PIN_12;
|
|
||||||
let mosi = p.PIN_11;
|
|
||||||
let clk = p.PIN_10;
|
|
||||||
let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
|
|
||||||
|
|
||||||
let nss = Output::new(p.PIN_3.degrade(), Level::High);
|
|
||||||
let reset = Output::new(p.PIN_15.degrade(), Level::High);
|
|
||||||
let dio1 = Input::new(p.PIN_20.degrade(), Pull::None);
|
|
||||||
let busy = Input::new(p.PIN_2.degrade(), Pull::None);
|
|
||||||
|
|
||||||
let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap();
|
|
||||||
|
|
||||||
let lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, 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(), embassy_rp::clocks::RoscRng);
|
|
||||||
|
|
||||||
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,108 +0,0 @@
|
|||||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a 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)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_rp::gpio::{Input, Level, Output, Pin, Pull};
|
|
||||||
use embassy_rp::spi::{Config, Spi};
|
|
||||||
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
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_rp::init(Default::default());
|
|
||||||
|
|
||||||
let miso = p.PIN_12;
|
|
||||||
let mosi = p.PIN_11;
|
|
||||||
let clk = p.PIN_10;
|
|
||||||
let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
|
|
||||||
|
|
||||||
let nss = Output::new(p.PIN_3.degrade(), Level::High);
|
|
||||||
let reset = Output::new(p.PIN_15.degrade(), Level::High);
|
|
||||||
let dio1 = Input::new(p.PIN_20.degrade(), Pull::None);
|
|
||||||
let busy = Input::new(p.PIN_2.degrade(), Pull::None);
|
|
||||||
|
|
||||||
let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), false, Delay).await {
|
|
||||||
Ok(l) => l,
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_indicator = Output::new(p.PIN_25, Level::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,96 +0,0 @@
|
|||||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
|
||||||
//! It demonstrates LORA P2P send functionality.
|
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_rp::gpio::{Input, Level, Output, Pin, Pull};
|
|
||||||
use embassy_rp::spi::{Config, Spi};
|
|
||||||
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
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let p = embassy_rp::init(Default::default());
|
|
||||||
|
|
||||||
let miso = p.PIN_12;
|
|
||||||
let mosi = p.PIN_11;
|
|
||||||
let clk = p.PIN_10;
|
|
||||||
let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
|
|
||||||
|
|
||||||
let nss = Output::new(p.PIN_3.degrade(), Level::High);
|
|
||||||
let reset = Output::new(p.PIN_15.degrade(), Level::High);
|
|
||||||
let dio1 = Input::new(p.PIN_20.degrade(), Pull::None);
|
|
||||||
let busy = Input::new(p.PIN_2.degrade(), Pull::None);
|
|
||||||
|
|
||||||
let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, 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),
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
|
|
||||||
//! It demonstrates LORA P2P send functionality using the second core, with data provided by the first core.
|
|
||||||
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Executor;
|
|
||||||
use embassy_lora::iv::GenericSx126xInterfaceVariant;
|
|
||||||
use embassy_rp::gpio::{AnyPin, Input, Level, Output, Pin, Pull};
|
|
||||||
use embassy_rp::multicore::{spawn_core1, Stack};
|
|
||||||
use embassy_rp::peripherals::SPI1;
|
|
||||||
use embassy_rp::spi::{Async, Config, Spi};
|
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
|
||||||
use embassy_sync::channel::Channel;
|
|
||||||
use embassy_time::{Delay, Timer};
|
|
||||||
use lora_phy::mod_params::*;
|
|
||||||
use lora_phy::sx1261_2::SX1261_2;
|
|
||||||
use lora_phy::LoRa;
|
|
||||||
use static_cell::StaticCell;
|
|
||||||
use {defmt_rtt as _, panic_probe as _};
|
|
||||||
|
|
||||||
static mut CORE1_STACK: Stack<4096> = Stack::new();
|
|
||||||
static EXECUTOR0: StaticCell<Executor> = StaticCell::new();
|
|
||||||
static EXECUTOR1: StaticCell<Executor> = StaticCell::new();
|
|
||||||
static CHANNEL: Channel<CriticalSectionRawMutex, [u8; 3], 1> = Channel::new();
|
|
||||||
|
|
||||||
const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region
|
|
||||||
|
|
||||||
#[cortex_m_rt::entry]
|
|
||||||
fn main() -> ! {
|
|
||||||
let p = embassy_rp::init(Default::default());
|
|
||||||
|
|
||||||
let miso = p.PIN_12;
|
|
||||||
let mosi = p.PIN_11;
|
|
||||||
let clk = p.PIN_10;
|
|
||||||
let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
|
|
||||||
|
|
||||||
let nss = Output::new(p.PIN_3.degrade(), Level::High);
|
|
||||||
let reset = Output::new(p.PIN_15.degrade(), Level::High);
|
|
||||||
let dio1 = Input::new(p.PIN_20.degrade(), Pull::None);
|
|
||||||
let busy = Input::new(p.PIN_2.degrade(), Pull::None);
|
|
||||||
|
|
||||||
let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap();
|
|
||||||
|
|
||||||
spawn_core1(p.CORE1, unsafe { &mut CORE1_STACK }, move || {
|
|
||||||
let executor1 = EXECUTOR1.init(Executor::new());
|
|
||||||
executor1.run(|spawner| unwrap!(spawner.spawn(core1_task(spi, iv))));
|
|
||||||
});
|
|
||||||
|
|
||||||
let executor0 = EXECUTOR0.init(Executor::new());
|
|
||||||
executor0.run(|spawner| unwrap!(spawner.spawn(core0_task())));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[embassy_executor::task]
|
|
||||||
async fn core0_task() {
|
|
||||||
info!("Hello from core 0");
|
|
||||||
loop {
|
|
||||||
CHANNEL.send([0x01u8, 0x02u8, 0x03u8]).await;
|
|
||||||
Timer::after_millis(60 * 1000).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[embassy_executor::task]
|
|
||||||
async fn core1_task(
|
|
||||||
spi: Spi<'static, SPI1, Async>,
|
|
||||||
iv: GenericSx126xInterfaceVariant<Output<'static, AnyPin>, Input<'static, AnyPin>>,
|
|
||||||
) {
|
|
||||||
info!("Hello from core 1");
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let buffer: [u8; 3] = CHANNEL.receive().await;
|
|
||||||
match lora.prepare_for_tx(&mdltn_params, 20, false).await {
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,8 +6,7 @@ license = "MIT OR Apache-2.0"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nightly"]
|
default = ["nightly"]
|
||||||
nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly",
|
nightly = ["embassy-stm32/nightly", "embassy-time/nightly", "embassy-time/unstable-traits", "embassy-executor/nightly", "dep:embedded-io-async"]
|
||||||
"embassy-lora", "lora-phy", "lorawan-device", "lorawan", "dep:embedded-io-async"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Change stm32l072cz to your chip name, if necessary.
|
# Change stm32l072cz to your chip name, if necessary.
|
||||||
@ -15,10 +14,6 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["
|
|||||||
embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] }
|
embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["defmt"] }
|
||||||
embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||||
embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
|
||||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt"], optional = true }
|
|
||||||
lora-phy = { version = "2", optional = true }
|
|
||||||
lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
|
|
||||||
lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"], optional = true }
|
|
||||||
|
|
||||||
defmt = "0.3"
|
defmt = "0.3"
|
||||||
defmt-rtt = "0.4"
|
defmt-rtt = "0.4"
|
||||||
|
@ -1,97 +0,0 @@
|
|||||||
//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio.
|
|
||||||
//! It demonstrates LORA P2P CAD functionality.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::Stm32l0InterfaceVariant;
|
|
||||||
use embassy_stm32::exti::{Channel, ExtiInput};
|
|
||||||
use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
|
|
||||||
use embassy_stm32::spi;
|
|
||||||
use embassy_stm32::time::khz;
|
|
||||||
use embassy_time::{Delay, Timer};
|
|
||||||
use lora_phy::mod_params::*;
|
|
||||||
use lora_phy::sx1276_7_8_9::SX1276_7_8_9;
|
|
||||||
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
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let mut config = embassy_stm32::Config::default();
|
|
||||||
config.rcc.hsi = true;
|
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
|
||||||
let p = embassy_stm32::init(config);
|
|
||||||
|
|
||||||
let mut spi_config = spi::Config::default();
|
|
||||||
spi_config.frequency = khz(200);
|
|
||||||
|
|
||||||
// SPI for sx1276
|
|
||||||
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
|
||||||
|
|
||||||
let irq_pin = Input::new(p.PB4.degrade(), Pull::Up);
|
|
||||||
let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade());
|
|
||||||
|
|
||||||
let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), false, Delay).await {
|
|
||||||
Ok(l) => l,
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_indicator = Output::new(p.PB5, Level::Low, Speed::Low);
|
|
||||||
let mut start_indicator = Output::new(p.PB6, Level::Low, Speed::Low);
|
|
||||||
|
|
||||||
start_indicator.set_high();
|
|
||||||
Timer::after_secs(5).await;
|
|
||||||
start_indicator.set_low();
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match lora.prepare_for_cad(&mdltn_params, true).await {
|
|
||||||
Ok(()) => {}
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
match lora.cad().await {
|
|
||||||
Ok(cad_activity_detected) => {
|
|
||||||
if cad_activity_detected {
|
|
||||||
info!("cad successful with activity detected")
|
|
||||||
} else {
|
|
||||||
info!("cad successful without activity detected")
|
|
||||||
}
|
|
||||||
debug_indicator.set_high();
|
|
||||||
Timer::after_secs(5).await;
|
|
||||||
debug_indicator.set_low();
|
|
||||||
}
|
|
||||||
Err(err) => info!("cad unsuccessful = {}", err),
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,85 +0,0 @@
|
|||||||
//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio.
|
|
||||||
//! It demonstrates LoRaWAN join functionality.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::Stm32l0InterfaceVariant;
|
|
||||||
use embassy_lora::LoraTimer;
|
|
||||||
use embassy_stm32::exti::{Channel, ExtiInput};
|
|
||||||
use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
|
|
||||||
use embassy_stm32::rng::Rng;
|
|
||||||
use embassy_stm32::time::khz;
|
|
||||||
use embassy_stm32::{bind_interrupts, peripherals, rng, spi};
|
|
||||||
use embassy_time::Delay;
|
|
||||||
use lora_phy::mod_params::*;
|
|
||||||
use lora_phy::sx1276_7_8_9::SX1276_7_8_9;
|
|
||||||
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 _};
|
|
||||||
|
|
||||||
bind_interrupts!(struct Irqs {
|
|
||||||
RNG_LPUART1 => rng::InterruptHandler<peripherals::RNG>;
|
|
||||||
});
|
|
||||||
|
|
||||||
const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let mut config = embassy_stm32::Config::default();
|
|
||||||
config.rcc.hsi = true;
|
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
|
||||||
let p = embassy_stm32::init(config);
|
|
||||||
|
|
||||||
let mut spi_config = spi::Config::default();
|
|
||||||
spi_config.frequency = khz(200);
|
|
||||||
|
|
||||||
// SPI for sx1276
|
|
||||||
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
|
||||||
|
|
||||||
let irq_pin = Input::new(p.PB4.degrade(), Pull::Up);
|
|
||||||
let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade());
|
|
||||||
|
|
||||||
let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap();
|
|
||||||
|
|
||||||
let lora = {
|
|
||||||
match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, 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,119 +0,0 @@
|
|||||||
//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 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)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::Stm32l0InterfaceVariant;
|
|
||||||
use embassy_stm32::exti::{Channel, ExtiInput};
|
|
||||||
use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
|
|
||||||
use embassy_stm32::spi;
|
|
||||||
use embassy_stm32::time::khz;
|
|
||||||
use embassy_time::{Delay, Timer};
|
|
||||||
use lora_phy::mod_params::*;
|
|
||||||
use lora_phy::sx1276_7_8_9::SX1276_7_8_9;
|
|
||||||
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
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let mut config = embassy_stm32::Config::default();
|
|
||||||
config.rcc.hsi = true;
|
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
|
||||||
let p = embassy_stm32::init(config);
|
|
||||||
|
|
||||||
let mut spi_config = spi::Config::default();
|
|
||||||
spi_config.frequency = khz(200);
|
|
||||||
|
|
||||||
// SPI for sx1276
|
|
||||||
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
|
||||||
|
|
||||||
let irq_pin = Input::new(p.PB4.degrade(), Pull::Up);
|
|
||||||
let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade());
|
|
||||||
|
|
||||||
let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), false, Delay).await {
|
|
||||||
Ok(l) => l,
|
|
||||||
Err(err) => {
|
|
||||||
info!("Radio error = {}", err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut debug_indicator = Output::new(p.PB5, Level::Low, Speed::Low);
|
|
||||||
let mut start_indicator = Output::new(p.PB6, 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,102 +0,0 @@
|
|||||||
//! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio.
|
|
||||||
//! It demonstrates LORA P2P send functionality.
|
|
||||||
#![no_std]
|
|
||||||
#![no_main]
|
|
||||||
#![macro_use]
|
|
||||||
#![feature(type_alias_impl_trait)]
|
|
||||||
|
|
||||||
use defmt::*;
|
|
||||||
use embassy_executor::Spawner;
|
|
||||||
use embassy_lora::iv::Stm32l0InterfaceVariant;
|
|
||||||
use embassy_stm32::exti::{Channel, ExtiInput};
|
|
||||||
use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed};
|
|
||||||
use embassy_stm32::spi;
|
|
||||||
use embassy_stm32::time::khz;
|
|
||||||
use embassy_time::Delay;
|
|
||||||
use lora_phy::mod_params::*;
|
|
||||||
use lora_phy::sx1276_7_8_9::SX1276_7_8_9;
|
|
||||||
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
|
|
||||||
|
|
||||||
#[embassy_executor::main]
|
|
||||||
async fn main(_spawner: Spawner) {
|
|
||||||
let mut config = embassy_stm32::Config::default();
|
|
||||||
config.rcc.hsi = true;
|
|
||||||
config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI;
|
|
||||||
let p = embassy_stm32::init(config);
|
|
||||||
|
|
||||||
let mut spi_config = spi::Config::default();
|
|
||||||
spi_config.frequency = khz(200);
|
|
||||||
|
|
||||||
// SPI for sx1276
|
|
||||||
let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config);
|
|
||||||
|
|
||||||
let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low);
|
|
||||||
let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low);
|
|
||||||
|
|
||||||
let irq_pin = Input::new(p.PB4.degrade(), Pull::Up);
|
|
||||||
let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade());
|
|
||||||
|
|
||||||
let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap();
|
|
||||||
|
|
||||||
let mut lora = {
|
|
||||||
match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, 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, 17, true).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),
|
|
||||||
}
|
|
||||||
}
|
|
@ -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-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-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-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 = "0.3"
|
||||||
defmt-rtt = "0.4"
|
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),
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user