aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-09-04 07:17:23 +0000
committerGitHub <[email protected]>2022-09-04 07:17:23 +0000
commit6264fe39a563b77e5a8fd873e7d29841af3b3c73 (patch)
treeb0f17887591523166f3ed3f7eea4330743c7b692 /examples
parent7d5c1fcebf875a5584518b99a70e8de980fba2ae (diff)
parent6cdff72d6d2becb3f8a4659571fd5e6a339cbefa (diff)
Merge #839
839: Misc LoRaWAN improvements r=lulf a=timokroeger Trying too get `embassy-lora` running on a [LoRa-E5 Dev Board](https://wiki.seeedstudio.com/LoRa_E5_Dev_Board/). I can see the join message arriving in the The Things Network console but the device does not receive the accept message yet. Opening this PR anyway because I think there are some nice things to decouple the lora crate from the nucleo board. `@lulf` Could you test if this PR breaks your LoRa setup? Marking as draft for the time being. Co-authored-by: Timo Kröger <[email protected]> Co-authored-by: Ulf Lilleengen <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32l0/Cargo.toml2
-rw-r--r--examples/stm32l0/src/bin/lorawan.rs2
-rw-r--r--examples/stm32wl/Cargo.toml2
-rw-r--r--examples/stm32wl/src/bin/lorawan.rs39
-rw-r--r--examples/stm32wl/src/bin/subghz.rs2
5 files changed, 37 insertions, 10 deletions
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index 11751a21d..6358fe865 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -14,7 +14,7 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
14embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 14embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
15embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true} 15embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
16 16
17lorawan-device = { version = "0.7.1", default-features = false, features = ["async"], optional = true } 17lorawan-device = { version = "0.8.0", default-features = false, features = ["async"], optional = true }
18lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"], optional = true } 18lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"], optional = true }
19 19
20defmt = "0.3" 20defmt = "0.3"
diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs
index 303558b96..00ff67f3f 100644
--- a/examples/stm32l0/src/bin/lorawan.rs
+++ b/examples/stm32l0/src/bin/lorawan.rs
@@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) {
47 let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap(); 47 let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap();
48 48
49 let region = region::EU868::default().into(); 49 let region = region::EU868::default().into();
50 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); 50 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG));
51 51
52 defmt::info!("Joining LoRaWAN network"); 52 defmt::info!("Joining LoRaWAN network");
53 53
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index 5f6679f4b..e2e7d4078 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -10,7 +10,7 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["de
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] } 10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wl55jc-cm4", "time-driver-any", "memory-x", "subghz", "unstable-pac", "exti"] }
11embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] } 11embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt"] }
12 12
13lorawan-device = { version = "0.7.1", default-features = false, features = ["async"] } 13lorawan-device = { version = "0.8.0", default-features = false, features = ["async"] }
14lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"] } 14lorawan = { version = "0.7.1", default-features = false, features = ["default-crypto"] }
15 15
16defmt = "0.3" 16defmt = "0.3"
diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs
index 7e8a8946d..9143e64da 100644
--- a/examples/stm32wl/src/bin/lorawan.rs
+++ b/examples/stm32wl/src/bin/lorawan.rs
@@ -9,7 +9,7 @@ use embassy_executor::Spawner;
9use embassy_lora::stm32wl::*; 9use embassy_lora::stm32wl::*;
10use embassy_lora::LoraTimer; 10use embassy_lora::LoraTimer;
11use embassy_stm32::dma::NoDma; 11use embassy_stm32::dma::NoDma;
12use embassy_stm32::gpio::{Level, Output, Pin, Speed}; 12use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed};
13use embassy_stm32::rng::Rng; 13use embassy_stm32::rng::Rng;
14use embassy_stm32::subghz::*; 14use embassy_stm32::subghz::*;
15use embassy_stm32::{interrupt, pac}; 15use embassy_stm32::{interrupt, pac};
@@ -17,6 +17,32 @@ use lorawan::default_crypto::DefaultFactory as Crypto;
17use lorawan_device::async_device::{region, Device, JoinMode}; 17use lorawan_device::async_device::{region, Device, JoinMode};
18use {defmt_rtt as _, panic_probe as _}; 18use {defmt_rtt as _, panic_probe as _};
19 19
20struct RadioSwitch<'a> {
21 ctrl1: Output<'a, AnyPin>,
22 ctrl2: Output<'a, AnyPin>,
23 ctrl3: Output<'a, AnyPin>,
24}
25
26impl<'a> RadioSwitch<'a> {
27 fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self {
28 Self { ctrl1, ctrl2, ctrl3 }
29 }
30}
31
32impl<'a> embassy_lora::stm32wl::RadioSwitch for RadioSwitch<'a> {
33 fn set_rx(&mut self) {
34 self.ctrl1.set_high();
35 self.ctrl2.set_low();
36 self.ctrl3.set_high();
37 }
38
39 fn set_tx(&mut self) {
40 self.ctrl1.set_high();
41 self.ctrl2.set_high();
42 self.ctrl3.set_high();
43 }
44}
45
20#[embassy_executor::main] 46#[embassy_executor::main]
21async fn main(_spawner: Spawner) { 47async fn main(_spawner: Spawner) {
22 let mut config = embassy_stm32::Config::default(); 48 let mut config = embassy_stm32::Config::default();
@@ -31,18 +57,19 @@ async fn main(_spawner: Spawner) {
31 let ctrl3 = Output::new(p.PC5.degrade(), Level::High, Speed::High); 57 let ctrl3 = Output::new(p.PC5.degrade(), Level::High, Speed::High);
32 let rfs = RadioSwitch::new(ctrl1, ctrl2, ctrl3); 58 let rfs = RadioSwitch::new(ctrl1, ctrl2, ctrl3);
33 59
34 let radio = SubGhz::new(p.SUBGHZSPI, p.PA5, p.PA7, p.PA6, NoDma, NoDma); 60 let radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma);
35
36 let irq = interrupt::take!(SUBGHZ_RADIO); 61 let irq = interrupt::take!(SUBGHZ_RADIO);
37 static mut RADIO_STATE: SubGhzState<'static> = SubGhzState::new(); 62
38 let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) }; 63 let mut radio_config = SubGhzRadioConfig::default();
64 radio_config.calibrate_image = CalibrateImage::ISM_863_870;
65 let radio = SubGhzRadio::new(radio, rfs, irq, radio_config).unwrap();
39 66
40 let mut region: region::Configuration = region::EU868::default().into(); 67 let mut region: region::Configuration = region::EU868::default().into();
41 68
42 // NOTE: This is specific for TTN, as they have a special RX1 delay 69 // NOTE: This is specific for TTN, as they have a special RX1 delay
43 region.set_receive_delay1(5000); 70 region.set_receive_delay1(5000);
44 71
45 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); 72 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), Rng::new(p.RNG));
46 73
47 // Depending on network, this might be part of JOIN 74 // Depending on network, this might be part of JOIN
48 device.set_datarate(region::DR::_0); // SF12 75 device.set_datarate(region::DR::_0); // SF12
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs
index c5e9bb597..8f674d796 100644
--- a/examples/stm32wl/src/bin/subghz.rs
+++ b/examples/stm32wl/src/bin/subghz.rs
@@ -72,7 +72,7 @@ async fn main(_spawner: Spawner) {
72 unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable(); 72 unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable();
73 }); 73 });
74 74
75 let mut radio = SubGhz::new(p.SUBGHZSPI, p.PA5, p.PA7, p.PA6, NoDma, NoDma); 75 let mut radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma);
76 76
77 defmt::info!("Radio ready for use"); 77 defmt::info!("Radio ready for use");
78 78