aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorceekdee <[email protected]>2023-04-25 13:51:19 -0500
committerceekdee <[email protected]>2023-04-25 13:51:19 -0500
commitf729d2d060043889eacb04dc924757a536eb247f (patch)
tree10d50fdcb5d0cb6244f9f6cd8c91b859a5adacaa /examples
parent73f25093c7793ad2e8bd6fceeca46d9b5b1031ad (diff)
Deprecate original LoRa drivers. Update rust-lorawan releases.
Diffstat (limited to 'examples')
-rw-r--r--examples/nrf52840/Cargo.toml4
-rw-r--r--examples/rp/Cargo.toml4
-rw-r--r--examples/stm32l0/Cargo.toml4
-rw-r--r--examples/stm32wl/Cargo.toml4
-rw-r--r--examples/stm32wl/src/bin/subghz.rs119
5 files changed, 8 insertions, 127 deletions
diff --git a/examples/nrf52840/Cargo.toml b/examples/nrf52840/Cargo.toml
index a1bcc4b6f..be8b5328e 100644
--- a/examples/nrf52840/Cargo.toml
+++ b/examples/nrf52840/Cargo.toml
@@ -20,8 +20,8 @@ embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defm
20embedded-io = "0.4.0" 20embedded-io = "0.4.0"
21embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt", "external-lora-phy"], optional = true } 21embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx126x", "time", "defmt", "external-lora-phy"], optional = true }
22lora-phy = { version = "1" } 22lora-phy = { version = "1" }
23lorawan-device = { version = "0.9.0", path = "../../../rust-lorawan/device", default-features = false, features = ["async", "external-lora-phy"], optional = true } 23lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
24lorawan = { version = "0.7.2", path = "../../../rust-lorawan/encoding", default-features = false, features = ["default-crypto"], optional = true } 24lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"], optional = true }
25 25
26defmt = "0.3" 26defmt = "0.3"
27defmt-rtt = "0.4" 27defmt-rtt = "0.4"
diff --git a/examples/rp/Cargo.toml b/examples/rp/Cargo.toml
index 5f0a397ea..45af8762e 100644
--- a/examples/rp/Cargo.toml
+++ b/examples/rp/Cargo.toml
@@ -17,8 +17,8 @@ embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
17embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" } 17embassy-usb-logger = { version = "0.1.0", path = "../../embassy-usb-logger" }
18embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt", "external-lora-phy"] } 18embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["time", "defmt", "external-lora-phy"] }
19lora-phy = { version = "1" } 19lora-phy = { version = "1" }
20lorawan-device = { version = "0.9.0", path = "../../../rust-lorawan/device", default-features = false, features = ["async", "external-lora-phy"] } 20lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] }
21lorawan = { version = "0.7.2", path = "../../../rust-lorawan/encoding", default-features = false, features = ["default-crypto"] } 21lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"] }
22 22
23defmt = "0.3" 23defmt = "0.3"
24defmt-rtt = "0.4" 24defmt-rtt = "0.4"
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index fe4b4f3c3..c51f1b904 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -15,8 +15,8 @@ embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["ni
15embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } 15embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
16embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt", "external-lora-phy"], optional = true } 16embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt", "external-lora-phy"], optional = true }
17lora-phy = { version = "1" } 17lora-phy = { version = "1" }
18lorawan-device = { version = "0.9.0", path = "../../../rust-lorawan/device", default-features = false, features = ["async", "external-lora-phy"], optional = true } 18lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"], optional = true }
19lorawan = { version = "0.7.2", path = "../../../rust-lorawan/encoding", default-features = false, features = ["default-crypto"], optional = true } 19lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"], optional = true }
20 20
21defmt = "0.3" 21defmt = "0.3"
22defmt-rtt = "0.4" 22defmt-rtt = "0.4"
diff --git a/examples/stm32wl/Cargo.toml b/examples/stm32wl/Cargo.toml
index 45e720f01..0eb24bc44 100644
--- a/examples/stm32wl/Cargo.toml
+++ b/examples/stm32wl/Cargo.toml
@@ -12,8 +12,8 @@ embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["
12embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" } 12embassy-embedded-hal = {version = "0.1.0", path = "../../embassy-embedded-hal" }
13embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt", "external-lora-phy"] } 13embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["stm32wl", "time", "defmt", "external-lora-phy"] }
14lora-phy = { version = "1" } 14lora-phy = { version = "1" }
15lorawan-device = { version = "0.9.0", path = "../../../rust-lorawan/device", default-features = false, features = ["async", "external-lora-phy"] } 15lorawan-device = { version = "0.10.0", default-features = false, features = ["async", "external-lora-phy"] }
16lorawan = { version = "0.7.2", path = "../../../rust-lorawan/encoding", default-features = false, features = ["default-crypto"] } 16lorawan = { version = "0.7.3", default-features = false, features = ["default-crypto"] }
17 17
18defmt = "0.3" 18defmt = "0.3"
19defmt-rtt = "0.4" 19defmt-rtt = "0.4"
diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs
deleted file mode 100644
index 32c8b5515..000000000
--- a/examples/stm32wl/src/bin/subghz.rs
+++ /dev/null
@@ -1,119 +0,0 @@
1#![no_std]
2#![no_main]
3#![macro_use]
4#![allow(dead_code)]
5#![feature(type_alias_impl_trait)]
6
7use defmt::*;
8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma;
10use embassy_stm32::exti::ExtiInput;
11use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
12use embassy_stm32::interrupt;
13use embassy_stm32::interrupt::{Interrupt, InterruptExt};
14use embassy_stm32::subghz::*;
15use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
16use embassy_sync::signal::Signal;
17use {defmt_rtt as _, panic_probe as _};
18
19const PING_DATA: &str = "PING";
20const DATA_LEN: u8 = PING_DATA.len() as u8;
21const PING_DATA_BYTES: &[u8] = PING_DATA.as_bytes();
22const PREAMBLE_LEN: u16 = 5 * 8;
23
24const RF_FREQ: RfFreq = RfFreq::from_frequency(867_500_000);
25
26const SYNC_WORD: [u8; 8] = [0x79, 0x80, 0x0C, 0xC0, 0x29, 0x95, 0xF8, 0x4A];
27const SYNC_WORD_LEN: u8 = SYNC_WORD.len() as u8;
28const SYNC_WORD_LEN_BITS: u8 = SYNC_WORD_LEN * 8;
29
30const TX_BUF_OFFSET: u8 = 128;
31const RX_BUF_OFFSET: u8 = 0;
32const LORA_PACKET_PARAMS: LoRaPacketParams = LoRaPacketParams::new()
33 .set_crc_en(true)
34 .set_preamble_len(PREAMBLE_LEN)
35 .set_payload_len(DATA_LEN)
36 .set_invert_iq(false)
37 .set_header_type(HeaderType::Fixed);
38
39const LORA_MOD_PARAMS: LoRaModParams = LoRaModParams::new()
40 .set_bw(LoRaBandwidth::Bw125)
41 .set_cr(CodingRate::Cr45)
42 .set_ldro_en(true)
43 .set_sf(SpreadingFactor::Sf7);
44
45// configuration for +10 dBm output power
46// see table 35 "PA optimal setting and operating modes"
47const PA_CONFIG: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp);
48
49const TCXO_MODE: TcxoMode = TcxoMode::new()
50 .set_txco_trim(TcxoTrim::Volts1pt7)
51 .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(10)));
52
53const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40);
54
55#[embassy_executor::main]
56async fn main(_spawner: Spawner) {
57 let mut config = embassy_stm32::Config::default();
58 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32;
59 let p = embassy_stm32::init(config);
60
61 let mut led1 = Output::new(p.PB15, Level::High, Speed::Low);
62 let mut led2 = Output::new(p.PB9, Level::Low, Speed::Low);
63 let mut led3 = Output::new(p.PB11, Level::Low, Speed::Low);
64
65 let button = Input::new(p.PA0, Pull::Up);
66 let mut pin = ExtiInput::new(button, p.EXTI0);
67
68 static IRQ_SIGNAL: Signal<CriticalSectionRawMutex, ()> = Signal::new();
69 let radio_irq = interrupt::take!(SUBGHZ_RADIO);
70 radio_irq.set_handler(|_| {
71 IRQ_SIGNAL.signal(());
72 unsafe { interrupt::SUBGHZ_RADIO::steal() }.disable();
73 });
74
75 let mut radio = SubGhz::new(p.SUBGHZSPI, NoDma, NoDma);
76
77 defmt::info!("Radio ready for use");
78
79 led1.set_low();
80
81 led2.set_high();
82
83 unwrap!(radio.set_standby(StandbyClk::Rc));
84 unwrap!(radio.set_tcxo_mode(&TCXO_MODE));
85 unwrap!(radio.set_standby(StandbyClk::Hse));
86 unwrap!(radio.set_regulator_mode(RegMode::Ldo));
87 unwrap!(radio.set_buffer_base_address(TX_BUF_OFFSET, RX_BUF_OFFSET));
88 unwrap!(radio.set_pa_config(&PA_CONFIG));
89 unwrap!(radio.set_pa_ocp(Ocp::Max60m));
90 unwrap!(radio.set_tx_params(&TX_PARAMS));
91 unwrap!(radio.set_packet_type(PacketType::LoRa));
92 unwrap!(radio.set_lora_sync_word(LoRaSyncWord::Public));
93 unwrap!(radio.set_lora_mod_params(&LORA_MOD_PARAMS));
94 unwrap!(radio.set_lora_packet_params(&LORA_PACKET_PARAMS));
95 unwrap!(radio.calibrate_image(CalibrateImage::ISM_863_870));
96 unwrap!(radio.set_rf_frequency(&RF_FREQ));
97
98 defmt::info!("Status: {:?}", unwrap!(radio.status()));
99
100 led2.set_low();
101
102 loop {
103 pin.wait_for_rising_edge().await;
104 led3.set_high();
105 unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone)));
106 unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES));
107 unwrap!(radio.set_tx(Timeout::DISABLED));
108
109 radio_irq.enable();
110 IRQ_SIGNAL.wait().await;
111
112 let (_, irq_status) = unwrap!(radio.irq_status());
113 if irq_status & Irq::TxDone.mask() != 0 {
114 defmt::info!("TX done");
115 }
116 unwrap!(radio.clear_irq_status(irq_status));
117 led3.set_low();
118 }
119}