aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-07-21 22:29:15 +0000
committerGitHub <[email protected]>2023-07-21 22:29:15 +0000
commit4db63677f6e56c52ea3d432542513967f5d93c69 (patch)
treead109082d957fced3b0e9a33ba74f3a47ea1da54 /examples
parent4d1d125f4157084668a949f9bc24e4417628f9fe (diff)
parentf4d6a23f92c8f6d3eb97a09e5bc51bac5e8d6837 (diff)
Merge pull request #1658 from xoviat/mac
implement most infra for wpan mac
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32wb/Cargo.toml9
-rw-r--r--examples/stm32wb/src/bin/mac_ffd.rs37
-rw-r--r--examples/stm32wb/src/bin/mac_ffd_net.rs170
-rw-r--r--examples/stm32wb/src/bin/mac_rfd.rs36
4 files changed, 201 insertions, 51 deletions
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index becf2d3fb..7c0b83e65 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -10,6 +10,7 @@ embassy-executor = { version = "0.2.0", path = "../../embassy-executor", feature
10embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.2", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32wb55rg", "time-driver-any", "memory-x", "exti"] }
12embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] } 12embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", features = ["defmt", "stm32wb55rg"] }
13embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "udp", "medium-ieee802154", "nightly"], optional=true }
13 14
14defmt = "0.3" 15defmt = "0.3"
15defmt-rtt = "0.4" 16defmt-rtt = "0.4"
@@ -20,11 +21,11 @@ embedded-hal = "0.2.6"
20panic-probe = { version = "0.3", features = ["print-defmt"] } 21panic-probe = { version = "0.3", features = ["print-defmt"] }
21futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 22futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
22heapless = { version = "0.7.5", default-features = false } 23heapless = { version = "0.7.5", default-features = false }
23 24static_cell = { version = "1.1", features = ["nightly"]}
24 25
25[features] 26[features]
26default = ["ble", "mac"] 27default = ["ble", "mac"]
27mac = ["embassy-stm32-wpan/mac"] 28mac = ["embassy-stm32-wpan/mac", "dep:embassy-net"]
28ble = ["embassy-stm32-wpan/ble"] 29ble = ["embassy-stm32-wpan/ble"]
29 30
30[[bin]] 31[[bin]]
@@ -40,6 +41,10 @@ name = "mac_ffd"
40required-features = ["mac"] 41required-features = ["mac"]
41 42
42[[bin]] 43[[bin]]
44name = "mac_ffd_net"
45required-features = ["mac"]
46
47[[bin]]
43name = "eddystone_beacon" 48name = "eddystone_beacon"
44required-features = ["ble"] 49required-features = ["ble"]
45 50
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs
index bc71e29aa..1379ac6ba 100644
--- a/examples/stm32wb/src/bin/mac_ffd.rs
+++ b/examples/stm32wb/src/bin/mac_ffd.rs
@@ -73,10 +73,7 @@ async fn main(spawner: Spawner) {
73 }) 73 })
74 .await 74 .await
75 .unwrap(); 75 .unwrap();
76 { 76 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
77 let evt = mbox.mac_subsystem.read().await;
78 defmt::info!("{:#x}", evt.mac_event());
79 }
80 77
81 info!("setting extended address"); 78 info!("setting extended address");
82 let extended_address: u64 = 0xACDE480000000001; 79 let extended_address: u64 = 0xACDE480000000001;
@@ -87,10 +84,7 @@ async fn main(spawner: Spawner) {
87 }) 84 })
88 .await 85 .await
89 .unwrap(); 86 .unwrap();
90 { 87 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
91 let evt = mbox.mac_subsystem.read().await;
92 defmt::info!("{:#x}", evt.mac_event());
93 }
94 88
95 info!("setting short address"); 89 info!("setting short address");
96 let short_address: u16 = 0x1122; 90 let short_address: u16 = 0x1122;
@@ -101,10 +95,7 @@ async fn main(spawner: Spawner) {
101 }) 95 })
102 .await 96 .await
103 .unwrap(); 97 .unwrap();
104 { 98 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
105 let evt = mbox.mac_subsystem.read().await;
106 defmt::info!("{:#x}", evt.mac_event());
107 }
108 99
109 info!("setting association permit"); 100 info!("setting association permit");
110 let association_permit: bool = true; 101 let association_permit: bool = true;
@@ -115,10 +106,7 @@ async fn main(spawner: Spawner) {
115 }) 106 })
116 .await 107 .await
117 .unwrap(); 108 .unwrap();
118 { 109 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
119 let evt = mbox.mac_subsystem.read().await;
120 defmt::info!("{:#x}", evt.mac_event());
121 }
122 110
123 info!("setting TX power"); 111 info!("setting TX power");
124 let transmit_power: i8 = 2; 112 let transmit_power: i8 = 2;
@@ -129,10 +117,7 @@ async fn main(spawner: Spawner) {
129 }) 117 })
130 .await 118 .await
131 .unwrap(); 119 .unwrap();
132 { 120 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
133 let evt = mbox.mac_subsystem.read().await;
134 defmt::info!("{:#x}", evt.mac_event());
135 }
136 121
137 info!("starting FFD device"); 122 info!("starting FFD device");
138 mbox.mac_subsystem 123 mbox.mac_subsystem
@@ -147,10 +132,7 @@ async fn main(spawner: Spawner) {
147 }) 132 })
148 .await 133 .await
149 .unwrap(); 134 .unwrap();
150 { 135 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
151 let evt = mbox.mac_subsystem.read().await;
152 defmt::info!("{:#x}", evt.mac_event());
153 }
154 136
155 info!("setting RX on when idle"); 137 info!("setting RX on when idle");
156 let rx_on_while_idle: bool = true; 138 let rx_on_while_idle: bool = true;
@@ -161,14 +143,11 @@ async fn main(spawner: Spawner) {
161 }) 143 })
162 .await 144 .await
163 .unwrap(); 145 .unwrap();
164 { 146 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
165 let evt = mbox.mac_subsystem.read().await;
166 defmt::info!("{:#x}", evt.mac_event());
167 }
168 147
169 loop { 148 loop {
170 let evt = mbox.mac_subsystem.read().await; 149 let evt = mbox.mac_subsystem.read().await;
171 if let Ok(evt) = evt.mac_event() { 150 if let Ok(evt) = evt {
172 defmt::info!("parsed mac event"); 151 defmt::info!("parsed mac event");
173 defmt::info!("{:#x}", evt); 152 defmt::info!("{:#x}", evt);
174 153
diff --git a/examples/stm32wb/src/bin/mac_ffd_net.rs b/examples/stm32wb/src/bin/mac_ffd_net.rs
new file mode 100644
index 000000000..bbcd0a70f
--- /dev/null
+++ b/examples/stm32wb/src/bin/mac_ffd_net.rs
@@ -0,0 +1,170 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::mac::commands::{ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::mac::typedefs::{MacChannel, PanId, PibId};
11use embassy_stm32_wpan::mac::{self, Runner};
12use embassy_stm32_wpan::sub::mm;
13use embassy_stm32_wpan::TlMbox;
14use static_cell::make_static;
15use {defmt_rtt as _, panic_probe as _};
16
17bind_interrupts!(struct Irqs{
18 IPCC_C1_RX => ReceiveInterruptHandler;
19 IPCC_C1_TX => TransmitInterruptHandler;
20});
21
22#[embassy_executor::task]
23async fn run_mm_queue(memory_manager: mm::MemoryManager) {
24 memory_manager.run_queue().await;
25}
26
27#[embassy_executor::task]
28async fn run_mac(runner: &'static Runner<'static>) {
29 runner.run().await;
30}
31
32#[embassy_executor::main]
33async fn main(spawner: Spawner) {
34 /*
35 How to make this work:
36
37 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
38 - Download and Install STM32CubeProgrammer.
39 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
40 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
41 - Open STM32CubeProgrammer
42 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
43 - Once complete, click connect to connect to the device.
44 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
45 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
46 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
47 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
48 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
49 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
50 - Select "Start Wireless Stack".
51 - Disconnect from the device.
52 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
53 - Run this example.
54
55 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
56 */
57
58 let p = embassy_stm32::init(Default::default());
59 info!("Hello World!");
60
61 let config = Config::default();
62 let mbox = TlMbox::init(p.IPCC, Irqs, config);
63
64 spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
65
66 let sys_event = mbox.sys_subsystem.read().await;
67 info!("sys event: {}", sys_event.payload());
68
69 core::mem::drop(sys_event);
70
71 let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
72 info!("initialized mac: {}", result);
73
74 info!("resetting");
75 mbox.mac_subsystem
76 .send_command(&ResetRequest {
77 set_default_pib: true,
78 ..Default::default()
79 })
80 .await
81 .unwrap();
82 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
83
84 info!("setting extended address");
85 let extended_address: u64 = 0xACDE480000000001;
86 mbox.mac_subsystem
87 .send_command(&SetRequest {
88 pib_attribute_ptr: &extended_address as *const _ as *const u8,
89 pib_attribute: PibId::ExtendedAddress,
90 })
91 .await
92 .unwrap();
93 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
94
95 info!("setting short address");
96 let short_address: u16 = 0x1122;
97 mbox.mac_subsystem
98 .send_command(&SetRequest {
99 pib_attribute_ptr: &short_address as *const _ as *const u8,
100 pib_attribute: PibId::ShortAddress,
101 })
102 .await
103 .unwrap();
104 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
105
106 info!("setting association permit");
107 let association_permit: bool = true;
108 mbox.mac_subsystem
109 .send_command(&SetRequest {
110 pib_attribute_ptr: &association_permit as *const _ as *const u8,
111 pib_attribute: PibId::AssociationPermit,
112 })
113 .await
114 .unwrap();
115 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
116
117 info!("setting TX power");
118 let transmit_power: i8 = 2;
119 mbox.mac_subsystem
120 .send_command(&SetRequest {
121 pib_attribute_ptr: &transmit_power as *const _ as *const u8,
122 pib_attribute: PibId::TransmitPower,
123 })
124 .await
125 .unwrap();
126 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
127
128 info!("starting FFD device");
129 mbox.mac_subsystem
130 .send_command(&StartRequest {
131 pan_id: PanId([0x1A, 0xAA]),
132 channel_number: MacChannel::Channel16,
133 beacon_order: 0x0F,
134 superframe_order: 0x0F,
135 pan_coordinator: true,
136 battery_life_extension: false,
137 ..Default::default()
138 })
139 .await
140 .unwrap();
141 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
142
143 info!("setting RX on when idle");
144 let rx_on_while_idle: bool = true;
145 mbox.mac_subsystem
146 .send_command(&SetRequest {
147 pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
148 pib_attribute: PibId::RxOnWhenIdle,
149 })
150 .await
151 .unwrap();
152 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
153
154 let tx_queue = [
155 make_static!([0u8; 127]),
156 make_static!([0u8; 127]),
157 make_static!([0u8; 127]),
158 make_static!([0u8; 127]),
159 make_static!([0u8; 127]),
160 ];
161
162 let runner = make_static!(Runner::new(mbox.mac_subsystem, tx_queue));
163
164 spawner.spawn(run_mac(runner)).unwrap();
165
166 let (driver, control) = mac::new(runner).await;
167
168 let _ = driver;
169 let _ = control;
170}
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs
index 7cb401d89..4d8b6601a 100644
--- a/examples/stm32wb/src/bin/mac_rfd.rs
+++ b/examples/stm32wb/src/bin/mac_rfd.rs
@@ -75,10 +75,7 @@ async fn main(spawner: Spawner) {
75 }) 75 })
76 .await 76 .await
77 .unwrap(); 77 .unwrap();
78 { 78 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
79 let evt = mbox.mac_subsystem.read().await;
80 defmt::info!("{:#x}", evt.mac_event());
81 }
82 79
83 info!("setting extended address"); 80 info!("setting extended address");
84 let extended_address: u64 = 0xACDE480000000002; 81 let extended_address: u64 = 0xACDE480000000002;
@@ -89,10 +86,7 @@ async fn main(spawner: Spawner) {
89 }) 86 })
90 .await 87 .await
91 .unwrap(); 88 .unwrap();
92 { 89 defmt::info!("{:#x}", mbox.mac_subsystem.read().await.unwrap());
93 let evt = mbox.mac_subsystem.read().await;
94 defmt::info!("{:#x}", evt.mac_event());
95 }
96 90
97 info!("getting extended address"); 91 info!("getting extended address");
98 mbox.mac_subsystem 92 mbox.mac_subsystem
@@ -104,10 +98,10 @@ async fn main(spawner: Spawner) {
104 .unwrap(); 98 .unwrap();
105 99
106 { 100 {
107 let evt = mbox.mac_subsystem.read().await; 101 let evt = mbox.mac_subsystem.read().await.unwrap();
108 info!("{:#x}", evt.mac_event()); 102 info!("{:#x}", evt);
109 103
110 if let Ok(MacEvent::MlmeGetCnf(evt)) = evt.mac_event() { 104 if let MacEvent::MlmeGetCnf(evt) = evt {
111 if evt.pib_attribute_value_len == 8 { 105 if evt.pib_attribute_value_len == 8 {
112 let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) }; 106 let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
113 107
@@ -132,10 +126,10 @@ async fn main(spawner: Spawner) {
132 info!("{}", a); 126 info!("{}", a);
133 mbox.mac_subsystem.send_command(&a).await.unwrap(); 127 mbox.mac_subsystem.send_command(&a).await.unwrap();
134 let short_addr = { 128 let short_addr = {
135 let evt = mbox.mac_subsystem.read().await; 129 let evt = mbox.mac_subsystem.read().await.unwrap();
136 info!("{:#x}", evt.mac_event()); 130 info!("{:#x}", evt);
137 131
138 if let Ok(MacEvent::MlmeAssociateCnf(conf)) = evt.mac_event() { 132 if let MacEvent::MlmeAssociateCnf(conf) = evt {
139 conf.assoc_short_address 133 conf.assoc_short_address
140 } else { 134 } else {
141 defmt::panic!() 135 defmt::panic!()
@@ -151,8 +145,8 @@ async fn main(spawner: Spawner) {
151 .await 145 .await
152 .unwrap(); 146 .unwrap();
153 { 147 {
154 let evt = mbox.mac_subsystem.read().await; 148 let evt = mbox.mac_subsystem.read().await.unwrap();
155 info!("{:#x}", evt.mac_event()); 149 info!("{:#x}", evt);
156 } 150 }
157 151
158 info!("sending data"); 152 info!("sending data");
@@ -175,12 +169,14 @@ async fn main(spawner: Spawner) {
175 .await 169 .await
176 .unwrap(); 170 .unwrap();
177 { 171 {
178 let evt = mbox.mac_subsystem.read().await; 172 let evt = mbox.mac_subsystem.read().await.unwrap();
179 info!("{:#x}", evt.mac_event()); 173 info!("{:#x}", evt);
180 } 174 }
181 175
182 loop { 176 loop {
183 let evt = mbox.mac_subsystem.read().await; 177 match mbox.mac_subsystem.read().await {
184 info!("{:#x}", evt.mac_event()); 178 Ok(evt) => info!("{:#x}", evt),
179 _ => continue,
180 };
185 } 181 }
186} 182}