diff options
Diffstat (limited to 'examples/stm32l0/src/bin/lora_lorawan.rs')
| -rw-r--r-- | examples/stm32l0/src/bin/lora_lorawan.rs | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/examples/stm32l0/src/bin/lora_lorawan.rs b/examples/stm32l0/src/bin/lora_lorawan.rs deleted file mode 100644 index 4365c4cf6..000000000 --- a/examples/stm32l0/src/bin/lora_lorawan.rs +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | //! This example runs on the STM32 LoRa Discovery board, which has a builtin Semtech Sx1276 radio. | ||
| 2 | //! It demonstrates LoRaWAN join functionality. | ||
| 3 | #![no_std] | ||
| 4 | #![no_main] | ||
| 5 | #![macro_use] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_lora::iv::Stm32l0InterfaceVariant; | ||
| 11 | use embassy_lora::LoraTimer; | ||
| 12 | use embassy_stm32::exti::{Channel, ExtiInput}; | ||
| 13 | use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; | ||
| 14 | use embassy_stm32::rng::Rng; | ||
| 15 | use embassy_stm32::time::khz; | ||
| 16 | use embassy_stm32::{bind_interrupts, peripherals, rng, spi}; | ||
| 17 | use embassy_time::Delay; | ||
| 18 | use lora_phy::mod_params::*; | ||
| 19 | use lora_phy::sx1276_7_8_9::SX1276_7_8_9; | ||
| 20 | use lora_phy::LoRa; | ||
| 21 | use lorawan::default_crypto::DefaultFactory as Crypto; | ||
| 22 | use lorawan_device::async_device::lora_radio::LoRaRadio; | ||
| 23 | use lorawan_device::async_device::{region, Device, JoinMode}; | ||
| 24 | use lorawan_device::{AppEui, AppKey, DevEui}; | ||
| 25 | use {defmt_rtt as _, panic_probe as _}; | ||
| 26 | |||
| 27 | bind_interrupts!(struct Irqs { | ||
| 28 | RNG_LPUART1 => rng::InterruptHandler<peripherals::RNG>; | ||
| 29 | }); | ||
| 30 | |||
| 31 | const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region | ||
| 32 | |||
| 33 | #[embassy_executor::main] | ||
| 34 | async fn main(_spawner: Spawner) { | ||
| 35 | let mut config = embassy_stm32::Config::default(); | ||
| 36 | config.rcc.hsi = true; | ||
| 37 | config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI; | ||
| 38 | let p = embassy_stm32::init(config); | ||
| 39 | |||
| 40 | let mut spi_config = spi::Config::default(); | ||
| 41 | spi_config.frequency = khz(200); | ||
| 42 | |||
| 43 | // SPI for sx1276 | ||
| 44 | let spi = spi::Spi::new(p.SPI1, p.PB3, p.PA7, p.PA6, p.DMA1_CH3, p.DMA1_CH2, spi_config); | ||
| 45 | |||
| 46 | let nss = Output::new(p.PA15.degrade(), Level::High, Speed::Low); | ||
| 47 | let reset = Output::new(p.PC0.degrade(), Level::High, Speed::Low); | ||
| 48 | |||
| 49 | let irq_pin = Input::new(p.PB4.degrade(), Pull::Up); | ||
| 50 | let irq = ExtiInput::new(irq_pin, p.EXTI4.degrade()); | ||
| 51 | |||
| 52 | let iv = Stm32l0InterfaceVariant::new(nss, reset, irq, None, None).unwrap(); | ||
| 53 | |||
| 54 | let lora = { | ||
| 55 | match LoRa::new(SX1276_7_8_9::new(BoardType::Stm32l0Sx1276, spi, iv), true, Delay).await { | ||
| 56 | Ok(l) => l, | ||
| 57 | Err(err) => { | ||
| 58 | info!("Radio error = {}", err); | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | } | ||
| 62 | }; | ||
| 63 | |||
| 64 | let radio = LoRaRadio::new(lora); | ||
| 65 | let region: region::Configuration = region::Configuration::new(LORAWAN_REGION); | ||
| 66 | let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG, Irqs)); | ||
| 67 | |||
| 68 | defmt::info!("Joining LoRaWAN network"); | ||
| 69 | |||
| 70 | // TODO: Adjust the EUI and Keys according to your network credentials | ||
| 71 | match device | ||
| 72 | .join(&JoinMode::OTAA { | ||
| 73 | deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 74 | appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 75 | appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]), | ||
| 76 | }) | ||
| 77 | .await | ||
| 78 | { | ||
| 79 | Ok(()) => defmt::info!("LoRaWAN network joined"), | ||
| 80 | Err(err) => { | ||
| 81 | info!("Radio error = {}", err); | ||
| 82 | return; | ||
| 83 | } | ||
| 84 | }; | ||
| 85 | } | ||
