diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-29 16:26:31 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-11-29 16:26:31 +0100 |
| commit | 1b9925e3da0ec42b770f736cd22325203c97cb47 (patch) | |
| tree | 2b03eb826cd9a9fce945921cff9c04a7e59f98f1 /examples/stm32wl | |
| parent | b4bc9ac028568dfb3896dfb00cbd1e181863fd64 (diff) | |
Move embassy-lora, lora examples to lora-phy repo.
Diffstat (limited to 'examples/stm32wl')
| -rw-r--r-- | examples/stm32wl/Cargo.toml | 4 | ||||
| -rw-r--r-- | examples/stm32wl/src/bin/lora_lorawan.rs | 95 | ||||
| -rw-r--r-- | examples/stm32wl/src/bin/lora_p2p_receive.rs | 133 | ||||
| -rw-r--r-- | examples/stm32wl/src/bin/lora_p2p_send.rs | 116 |
4 files changed, 0 insertions, 348 deletions
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml index 645ca84d3..4f608fcf1 100644 --- a/examples/stm32wl/Cargo.toml +++ b/examples/stm32wl/Cargo.toml | |||
| @@ -11,10 +11,6 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de | |||
| 11 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.3.3", path = "../../embassy-executor", features = ["nightly", "arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["nightly", "unstable-traits", "defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } |
| 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } | 13 | embassy-embedded-hal = { version = "0.1.0", path = "../../embassy-embedded-hal" } |
| 14 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } | ||
| 15 | lora-phy = { version = "2" } | ||
| 16 | lorawan-device = { version = "0.11.0", default-features = false, features = ["async", "external-lora-phy"] } | ||
| 17 | lorawan = { version = "0.7.4", default-features = false, features = ["default-crypto"] } | ||
| 18 | 14 | ||
| 19 | defmt = "0.3" | 15 | defmt = "0.3" |
| 20 | defmt-rtt = "0.4" | 16 | defmt-rtt = "0.4" |
diff --git a/examples/stm32wl/src/bin/lora_lorawan.rs b/examples/stm32wl/src/bin/lora_lorawan.rs deleted file mode 100644 index 348e3cdce..000000000 --- a/examples/stm32wl/src/bin/lora_lorawan.rs +++ /dev/null | |||
| @@ -1,95 +0,0 @@ | |||
| 1 | //! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LoRaWAN join functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait, async_fn_in_trait)] | ||
| 7 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 8 | |||
| 9 | use defmt::info; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; | ||
| 12 | use embassy_lora::LoraTimer; | ||
| 13 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | ||
| 14 | use embassy_stm32::rng::{self, Rng}; | ||
| 15 | use embassy_stm32::spi::Spi; | ||
| 16 | use embassy_stm32::time::Hertz; | ||
| 17 | use embassy_stm32::{bind_interrupts, peripherals}; | ||
| 18 | use embassy_time::Delay; | ||
| 19 | use lora_phy::mod_params::*; | ||
| 20 | use lora_phy::sx1261_2::SX1261_2; | ||
| 21 | use lora_phy::LoRa; | ||
| 22 | use lorawan::default_crypto::DefaultFactory as Crypto; | ||
| 23 | use lorawan_device::async_device::lora_radio::LoRaRadio; | ||
| 24 | use lorawan_device::async_device::{region, Device, JoinMode}; | ||
| 25 | use lorawan_device::{AppEui, AppKey, DevEui}; | ||
| 26 | use {defmt_rtt as _, panic_probe as _}; | ||
| 27 | |||
| 28 | const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region | ||
| 29 | |||
| 30 | bind_interrupts!(struct Irqs{ | ||
| 31 | SUBGHZ_RADIO => InterruptHandler; | ||
| 32 | RNG => rng::InterruptHandler<peripherals::RNG>; | ||
| 33 | }); | ||
| 34 | |||
| 35 | #[embassy_executor::main] | ||
| 36 | async fn main(_spawner: Spawner) { | ||
| 37 | let mut config = embassy_stm32::Config::default(); | ||
| 38 | { | ||
| 39 | use embassy_stm32::rcc::*; | ||
| 40 | config.rcc.hse = Some(Hse { | ||
| 41 | freq: Hertz(32_000_000), | ||
| 42 | mode: HseMode::Bypass, | ||
| 43 | prescaler: HsePrescaler::DIV1, | ||
| 44 | }); | ||
| 45 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 46 | config.rcc.pll = Some(Pll { | ||
| 47 | source: PllSource::HSE, | ||
| 48 | prediv: PllPreDiv::DIV2, | ||
| 49 | mul: PllMul::MUL6, | ||
| 50 | divp: None, | ||
| 51 | divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG | ||
| 52 | divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) | ||
| 53 | }); | ||
| 54 | } | ||
| 55 | let p = embassy_stm32::init(config); | ||
| 56 | |||
| 57 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | ||
| 58 | |||
| 59 | // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx | ||
| 60 | let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); | ||
| 61 | let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); | ||
| 62 | let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); | ||
| 63 | let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); | ||
| 64 | |||
| 65 | let lora = { | ||
| 66 | match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), true, Delay).await { | ||
| 67 | Ok(l) => l, | ||
| 68 | Err(err) => { | ||
| 69 | info!("Radio error = {}", err); | ||
| 70 | return; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | }; | ||
| 74 | let radio = LoRaRadio::new(lora); | ||
| 75 | let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); | ||
| 76 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); | ||
| 77 | |||
| 78 | defmt::info!("Joining LoRaWAN network"); | ||
| 79 | |||
| 80 | // TODO: Adjust the EUI and Keys according to your network credentials | ||
| 81 | match device | ||
| 82 | .join(&JoinMode::OTAA { | ||
| 83 | deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 84 | appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 85 | appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 86 | }) | ||
| 87 | .await | ||
| 88 | { | ||
| 89 | Ok(()) => defmt::info!("LoRaWAN network joined"), | ||
| 90 | Err(err) => { | ||
| 91 | info!("Radio error = {}", err); | ||
| 92 | return; | ||
| 93 | } | ||
| 94 | }; | ||
| 95 | } | ||
diff --git a/examples/stm32wl/src/bin/lora_p2p_receive.rs b/examples/stm32wl/src/bin/lora_p2p_receive.rs deleted file mode 100644 index c643ddb15..000000000 --- a/examples/stm32wl/src/bin/lora_p2p_receive.rs +++ /dev/null | |||
| @@ -1,133 +0,0 @@ | |||
| 1 | //! This example runs on the STM32WL board, which has a builtin Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P receive functionality in conjunction with the lora_p2p_send example. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait, async_fn_in_trait)] | ||
| 7 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 8 | |||
| 9 | use defmt::info; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; | ||
| 12 | use embassy_stm32::bind_interrupts; | ||
| 13 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | ||
| 14 | use embassy_stm32::spi::Spi; | ||
| 15 | use embassy_stm32::time::Hertz; | ||
| 16 | use embassy_time::{Delay, Timer}; | ||
| 17 | use lora_phy::mod_params::*; | ||
| 18 | use lora_phy::sx1261_2::SX1261_2; | ||
| 19 | use lora_phy::LoRa; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | ||
| 21 | |||
| 22 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 23 | |||
| 24 | bind_interrupts!(struct Irqs{ | ||
| 25 | SUBGHZ_RADIO => InterruptHandler; | ||
| 26 | }); | ||
| 27 | |||
| 28 | #[embassy_executor::main] | ||
| 29 | async fn main(_spawner: Spawner) { | ||
| 30 | let mut config = embassy_stm32::Config::default(); | ||
| 31 | { | ||
| 32 | use embassy_stm32::rcc::*; | ||
| 33 | config.rcc.hse = Some(Hse { | ||
| 34 | freq: Hertz(32_000_000), | ||
| 35 | mode: HseMode::Bypass, | ||
| 36 | prescaler: HsePrescaler::DIV1, | ||
| 37 | }); | ||
| 38 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 39 | config.rcc.pll = Some(Pll { | ||
| 40 | source: PllSource::HSE, | ||
| 41 | prediv: PllPreDiv::DIV2, | ||
| 42 | mul: PllMul::MUL6, | ||
| 43 | divp: None, | ||
| 44 | divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG | ||
| 45 | divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) | ||
| 46 | }); | ||
| 47 | } | ||
| 48 | let p = embassy_stm32::init(config); | ||
| 49 | |||
| 50 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | ||
| 51 | |||
| 52 | // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx | ||
| 53 | let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); | ||
| 54 | let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); | ||
| 55 | let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); | ||
| 56 | let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); | ||
| 57 | |||
| 58 | let mut lora = { | ||
| 59 | match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await { | ||
| 60 | Ok(l) => l, | ||
| 61 | Err(err) => { | ||
| 62 | info!("Radio error = {}", err); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | let mut debug_indicator = Output::new(p.PB9, Level::Low, Speed::Low); | ||
| 69 | let mut start_indicator = Output::new(p.PB15, Level::Low, Speed::Low); | ||
| 70 | |||
| 71 | start_indicator.set_high(); | ||
| 72 | Timer::after_secs(5).await; | ||
| 73 | start_indicator.set_low(); | ||
| 74 | |||
| 75 | let mut receiving_buffer = [00u8; 100]; | ||
| 76 | |||
| 77 | let mdltn_params = { | ||
| 78 | match lora.create_modulation_params( | ||
| 79 | SpreadingFactor::_10, | ||
| 80 | Bandwidth::_250KHz, | ||
| 81 | CodingRate::_4_8, | ||
| 82 | LORA_FREQUENCY_IN_HZ, | ||
| 83 | ) { | ||
| 84 | Ok(mp) => mp, | ||
| 85 | Err(err) => { | ||
| 86 | info!("Radio error = {}", err); | ||
| 87 | return; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | }; | ||
| 91 | |||
| 92 | let rx_pkt_params = { | ||
| 93 | match lora.create_rx_packet_params(4, false, receiving_buffer.len() as u8, true, false, &mdltn_params) { | ||
| 94 | Ok(pp) => pp, | ||
| 95 | Err(err) => { | ||
| 96 | info!("Radio error = {}", err); | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | } | ||
| 100 | }; | ||
| 101 | |||
| 102 | match lora | ||
| 103 | .prepare_for_rx(&mdltn_params, &rx_pkt_params, None, None, false) | ||
| 104 | .await | ||
| 105 | { | ||
| 106 | Ok(()) => {} | ||
| 107 | Err(err) => { | ||
| 108 | info!("Radio error = {}", err); | ||
| 109 | return; | ||
| 110 | } | ||
| 111 | }; | ||
| 112 | |||
| 113 | loop { | ||
| 114 | receiving_buffer = [00u8; 100]; | ||
| 115 | match lora.rx(&rx_pkt_params, &mut receiving_buffer).await { | ||
| 116 | Ok((received_len, _rx_pkt_status)) => { | ||
| 117 | if (received_len == 3) | ||
| 118 | && (receiving_buffer[0] == 0x01u8) | ||
| 119 | && (receiving_buffer[1] == 0x02u8) | ||
| 120 | && (receiving_buffer[2] == 0x03u8) | ||
| 121 | { | ||
| 122 | info!("rx successful"); | ||
| 123 | debug_indicator.set_high(); | ||
| 124 | Timer::after_secs(5).await; | ||
| 125 | debug_indicator.set_low(); | ||
| 126 | } else { | ||
| 127 | info!("rx unknown packet"); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | Err(err) => info!("rx unsuccessful = {}", err), | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
diff --git a/examples/stm32wl/src/bin/lora_p2p_send.rs b/examples/stm32wl/src/bin/lora_p2p_send.rs deleted file mode 100644 index 7fe8cea3e..000000000 --- a/examples/stm32wl/src/bin/lora_p2p_send.rs +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | //! This example runs on a STM32WL board, which has a builtin Semtech Sx1262 radio. | ||
| 2 | //! It demonstrates LORA P2P send functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait, async_fn_in_trait)] | ||
| 7 | #![allow(stable_features, unknown_lints, async_fn_in_trait)] | ||
| 8 | |||
| 9 | use defmt::info; | ||
| 10 | use embassy_executor::Spawner; | ||
| 11 | use embassy_lora::iv::{InterruptHandler, Stm32wlInterfaceVariant}; | ||
| 12 | use embassy_stm32::bind_interrupts; | ||
| 13 | use embassy_stm32::gpio::{Level, Output, Pin, Speed}; | ||
| 14 | use embassy_stm32::spi::Spi; | ||
| 15 | use embassy_stm32::time::Hertz; | ||
| 16 | use embassy_time::Delay; | ||
| 17 | use lora_phy::mod_params::*; | ||
| 18 | use lora_phy::sx1261_2::SX1261_2; | ||
| 19 | use lora_phy::LoRa; | ||
| 20 | use {defmt_rtt as _, panic_probe as _}; | ||
| 21 | |||
| 22 | const LORA_FREQUENCY_IN_HZ: u32 = 903_900_000; // warning: set this appropriately for the region | ||
| 23 | |||
| 24 | bind_interrupts!(struct Irqs{ | ||
| 25 | SUBGHZ_RADIO => InterruptHandler; | ||
| 26 | }); | ||
| 27 | |||
| 28 | #[embassy_executor::main] | ||
| 29 | async fn main(_spawner: Spawner) { | ||
| 30 | let mut config = embassy_stm32::Config::default(); | ||
| 31 | { | ||
| 32 | use embassy_stm32::rcc::*; | ||
| 33 | config.rcc.hse = Some(Hse { | ||
| 34 | freq: Hertz(32_000_000), | ||
| 35 | mode: HseMode::Bypass, | ||
| 36 | prescaler: HsePrescaler::DIV1, | ||
| 37 | }); | ||
| 38 | config.rcc.mux = ClockSrc::PLL1_R; | ||
| 39 | config.rcc.pll = Some(Pll { | ||
| 40 | source: PllSource::HSE, | ||
| 41 | prediv: PllPreDiv::DIV2, | ||
| 42 | mul: PllMul::MUL6, | ||
| 43 | divp: None, | ||
| 44 | divq: Some(PllQDiv::DIV2), // PLL1_Q clock (32 / 2 * 6 / 2), used for RNG | ||
| 45 | divr: Some(PllRDiv::DIV2), // sysclk 48Mhz clock (32 / 2 * 6 / 2) | ||
| 46 | }); | ||
| 47 | } | ||
| 48 | let p = embassy_stm32::init(config); | ||
| 49 | |||
| 50 | let spi = Spi::new_subghz(p.SUBGHZSPI, p.DMA1_CH1, p.DMA1_CH2); | ||
| 51 | |||
| 52 | // Set CTRL1 and CTRL3 for high-power transmission, while CTRL2 acts as an RF switch between tx and rx | ||
| 53 | let _ctrl1 = Output::new(p.PC4.degrade(), Level::Low, Speed::High); | ||
| 54 | let ctrl2 = Output::new(p.PC5.degrade(), Level::High, Speed::High); | ||
| 55 | let _ctrl3 = Output::new(p.PC3.degrade(), Level::High, Speed::High); | ||
| 56 | let iv = Stm32wlInterfaceVariant::new(Irqs, None, Some(ctrl2)).unwrap(); | ||
| 57 | |||
| 58 | let mut lora = { | ||
| 59 | match LoRa::new(SX1261_2::new(BoardType::Stm32wlSx1262, spi, iv), false, Delay).await { | ||
| 60 | Ok(l) => l, | ||
| 61 | Err(err) => { | ||
| 62 | info!("Radio error = {}", err); | ||
| 63 | return; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | let mdltn_params = { | ||
| 69 | match lora.create_modulation_params( | ||
| 70 | SpreadingFactor::_10, | ||
| 71 | Bandwidth::_250KHz, | ||
| 72 | CodingRate::_4_8, | ||
| 73 | LORA_FREQUENCY_IN_HZ, | ||
| 74 | ) { | ||
| 75 | Ok(mp) => mp, | ||
| 76 | Err(err) => { | ||
| 77 | info!("Radio error = {}", err); | ||
| 78 | return; | ||
| 79 | } | ||
| 80 | } | ||
| 81 | }; | ||
| 82 | |||
| 83 | let mut tx_pkt_params = { | ||
| 84 | match lora.create_tx_packet_params(4, false, true, false, &mdltn_params) { | ||
| 85 | Ok(pp) => pp, | ||
| 86 | Err(err) => { | ||
| 87 | info!("Radio error = {}", err); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | }; | ||
| 92 | |||
| 93 | match lora.prepare_for_tx(&mdltn_params, 20, false).await { | ||
| 94 | Ok(()) => {} | ||
| 95 | Err(err) => { | ||
| 96 | info!("Radio error = {}", err); | ||
| 97 | return; | ||
| 98 | } | ||
| 99 | }; | ||
| 100 | |||
| 101 | let buffer = [0x01u8, 0x02u8, 0x03u8]; | ||
| 102 | match lora.tx(&mdltn_params, &mut tx_pkt_params, &buffer, 0xffffff).await { | ||
| 103 | Ok(()) => { | ||
| 104 | info!("TX DONE"); | ||
| 105 | } | ||
| 106 | Err(err) => { | ||
| 107 | info!("Radio error = {}", err); | ||
| 108 | return; | ||
| 109 | } | ||
| 110 | }; | ||
| 111 | |||
| 112 | match lora.sleep(false).await { | ||
| 113 | Ok(()) => info!("Sleep successful"), | ||
| 114 | Err(err) => info!("Sleep unsuccessful = {}", err), | ||
| 115 | } | ||
| 116 | } | ||
