aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-07-17 20:14:06 -0500
committerxoviat <[email protected]>2023-07-17 20:14:06 -0500
commitd040871f7a078db94846305463c30a461f821d7f (patch)
tree4b3280994fb762542a37c47182461cbf6fa1f9a3 /examples
parent8f23b6faa6f04f83ece119e94335f892d516f6b3 (diff)
wpan: fix comp errors and impl. some of runner
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32wb/src/bin/mac_ffd_net.rs180
1 files changed, 180 insertions, 0 deletions
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..b1cf051bf
--- /dev/null
+++ b/examples/stm32wb/src/bin/mac_ffd_net.rs
@@ -0,0 +1,180 @@
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::{AssociateResponse, ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel};
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) {
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 {
83 let evt = mbox.mac_subsystem.read().await;
84 defmt::info!("{:#x}", evt.mac_event());
85 }
86
87 info!("setting extended address");
88 let extended_address: u64 = 0xACDE480000000001;
89 mbox.mac_subsystem
90 .send_command(&SetRequest {
91 pib_attribute_ptr: &extended_address as *const _ as *const u8,
92 pib_attribute: PibId::ExtendedAddress,
93 })
94 .await
95 .unwrap();
96 {
97 let evt = mbox.mac_subsystem.read().await;
98 defmt::info!("{:#x}", evt.mac_event());
99 }
100
101 info!("setting short address");
102 let short_address: u16 = 0x1122;
103 mbox.mac_subsystem
104 .send_command(&SetRequest {
105 pib_attribute_ptr: &short_address as *const _ as *const u8,
106 pib_attribute: PibId::ShortAddress,
107 })
108 .await
109 .unwrap();
110 {
111 let evt = mbox.mac_subsystem.read().await;
112 defmt::info!("{:#x}", evt.mac_event());
113 }
114
115 info!("setting association permit");
116 let association_permit: bool = true;
117 mbox.mac_subsystem
118 .send_command(&SetRequest {
119 pib_attribute_ptr: &association_permit as *const _ as *const u8,
120 pib_attribute: PibId::AssociationPermit,
121 })
122 .await
123 .unwrap();
124 {
125 let evt = mbox.mac_subsystem.read().await;
126 defmt::info!("{:#x}", evt.mac_event());
127 }
128
129 info!("setting TX power");
130 let transmit_power: i8 = 2;
131 mbox.mac_subsystem
132 .send_command(&SetRequest {
133 pib_attribute_ptr: &transmit_power as *const _ as *const u8,
134 pib_attribute: PibId::TransmitPower,
135 })
136 .await
137 .unwrap();
138 {
139 let evt = mbox.mac_subsystem.read().await;
140 defmt::info!("{:#x}", evt.mac_event());
141 }
142
143 info!("starting FFD device");
144 mbox.mac_subsystem
145 .send_command(&StartRequest {
146 pan_id: PanId([0x1A, 0xAA]),
147 channel_number: MacChannel::Channel16,
148 beacon_order: 0x0F,
149 superframe_order: 0x0F,
150 pan_coordinator: true,
151 battery_life_extension: false,
152 ..Default::default()
153 })
154 .await
155 .unwrap();
156 {
157 let evt = mbox.mac_subsystem.read().await;
158 defmt::info!("{:#x}", evt.mac_event());
159 }
160
161 info!("setting RX on when idle");
162 let rx_on_while_idle: bool = true;
163 mbox.mac_subsystem
164 .send_command(&SetRequest {
165 pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
166 pib_attribute: PibId::RxOnWhenIdle,
167 })
168 .await
169 .unwrap();
170 {
171 let evt = mbox.mac_subsystem.read().await;
172 defmt::info!("{:#x}", evt.mac_event());
173 }
174
175 let runner = make_static!(Runner::new(mbox.mac_subsystem));
176
177 spawner.spawn(run_mac(runner)).unwrap();
178
179 let (driver, control) = mac::new(runner).await;
180}