aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32wb/src/bin/mac_ffd.rs
diff options
context:
space:
mode:
authorgoueslati <[email protected]>2023-07-11 16:07:33 +0100
committergoueslati <[email protected]>2023-07-11 16:07:33 +0100
commit6f4172fbc1280fdd9190ccddcf3cf6f25788c7be (patch)
treef4503826cd87c9fb0958c966d4702d0d32d22578 /examples/stm32wb/src/bin/mac_ffd.rs
parent4aca7c8811b70e420280893784cdad2acbe326f9 (diff)
wip: added MAC commands
Diffstat (limited to 'examples/stm32wb/src/bin/mac_ffd.rs')
-rw-r--r--examples/stm32wb/src/bin/mac_ffd.rs174
1 files changed, 174 insertions, 0 deletions
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs
new file mode 100644
index 000000000..4100d1ac5
--- /dev/null
+++ b/examples/stm32wb/src/bin/mac_ffd.rs
@@ -0,0 +1,174 @@
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::sub::mac::commands::{ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::sub::mac::typedefs::PibId;
11use embassy_stm32_wpan::sub::mm;
12use embassy_stm32_wpan::TlMbox;
13use {defmt_rtt as _, panic_probe as _};
14
15bind_interrupts!(struct Irqs{
16 IPCC_C1_RX => ReceiveInterruptHandler;
17 IPCC_C1_TX => TransmitInterruptHandler;
18});
19
20#[embassy_executor::task]
21async fn run_mm_queue(memory_manager: mm::MemoryManager) {
22 memory_manager.run_queue().await;
23}
24
25#[embassy_executor::main]
26async fn main(spawner: Spawner) {
27 /*
28 How to make this work:
29
30 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
31 - Download and Install STM32CubeProgrammer.
32 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
33 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
34 - Open STM32CubeProgrammer
35 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
36 - Once complete, click connect to connect to the device.
37 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
38 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
39 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
40 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
41 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
42 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
43 - Select "Start Wireless Stack".
44 - Disconnect from the device.
45 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
46 - Run this example.
47
48 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
49 */
50
51 let p = embassy_stm32::init(Default::default());
52 info!("Hello World!");
53
54 let config = Config::default();
55 let mbox = TlMbox::init(p.IPCC, Irqs, config);
56
57 spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
58
59 let sys_event = mbox.sys_subsystem.read().await;
60 info!("sys event: {}", sys_event.payload());
61
62 core::mem::drop(sys_event);
63
64 let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
65 info!("initialized mac: {}", result);
66
67 info!("resetting");
68 let response = mbox
69 .mac_subsystem
70 .send_command(ResetRequest { set_default_pib: true })
71 .await;
72 info!("{}", response);
73
74 info!("setting extended address");
75 let extended_address: u64 = 0xACDE480000000001;
76 let response = mbox
77 .mac_subsystem
78 .send_command(SetRequest {
79 pib_attribute_ptr: &extended_address as *const _ as *const u8,
80 pib_attribute: PibId::ExtendedAddress,
81 })
82 .await;
83 info!("{}", response);
84
85 info!("setting short address");
86 let short_address: u16 = 0x1122;
87 let response = mbox
88 .mac_subsystem
89 .send_command(SetRequest {
90 pib_attribute_ptr: &short_address as *const _ as *const u8,
91 pib_attribute: PibId::ShortAddress,
92 })
93 .await;
94 info!("{}", response);
95
96 info!("setting association permit");
97 let association_permit: bool = true;
98 let response = mbox
99 .mac_subsystem
100 .send_command(SetRequest {
101 pib_attribute_ptr: &association_permit as *const _ as *const u8,
102 pib_attribute: PibId::AssociationPermit,
103 })
104 .await;
105 info!("{}", response);
106
107 info!("setting TX power");
108 let transmit_power: i8 = 2;
109 let response = mbox
110 .mac_subsystem
111 .send_command(SetRequest {
112 pib_attribute_ptr: &transmit_power as *const _ as *const u8,
113 pib_attribute: PibId::TransmitPower,
114 })
115 .await;
116 info!("{}", response);
117
118 info!("starting FFD device");
119 let response = mbox
120 .mac_subsystem
121 .send_command(StartRequest {
122 channel_number: 16,
123 beacon_order: 0x0F,
124 superframe_order: 0x0F,
125 pan_coordinator: true,
126 battery_life_extension: false,
127 ..Default::default()
128 })
129 .await;
130 info!("{}", response);
131
132 info!("setting RX on when idle");
133 let rx_on_while_idle: bool = true;
134 let response = mbox
135 .mac_subsystem
136 .send_command(SetRequest {
137 pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
138 pib_attribute: PibId::RxOnWhenIdle,
139 })
140 .await;
141 info!("{}", response);
142
143 // info!("association request");
144 // mbox.mac_subsystem
145 // .send_command(AssociateRequest {
146 // channel_number: 16,
147 // channel_page: 0,
148 // coord_addr_mode: 2,
149 // coord_address: MacAddress { short: [0x22, 0x11] },
150 // capability_information: 0x80,
151 // coord_pan_id: [0xAA, 0x1A],
152 // security_level: 0,
153
154 // key_id_mode: 0,
155 // key_index: 0,
156 // key_source: [0; 8],
157 // })
158 // .await;
159 // info!("reading");
160 // let result = mbox.mac_subsystem.read().await;
161 // info!("{}", result.payload());
162
163 //
164 // info!("starting ble...");
165 // mbox.ble_subsystem.t_write(0x0c, &[]).await;
166 //
167 // info!("waiting for ble...");
168 // let ble_event = mbox.ble_subsystem.tl_read().await;
169 //
170 // info!("ble event: {}", ble_event.payload());
171
172 info!("Test OK");
173 cortex_m::asm::bkpt();
174}