aboutsummaryrefslogtreecommitdiff
path: root/examples
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
parent4aca7c8811b70e420280893784cdad2acbe326f9 (diff)
wip: added MAC commands
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32wb/Cargo.toml2
-rw-r--r--examples/stm32wb/src/bin/mac_ffd.rs174
-rw-r--r--examples/stm32wb/src/bin/mac_rfd.rs (renamed from examples/stm32wb/src/bin/tl_mbox_mac_2.rs)65
3 files changed, 207 insertions, 34 deletions
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index 109734546..f23c8afa6 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -36,7 +36,7 @@ name = "tl_mbox_mac"
36required-features = ["mac"] 36required-features = ["mac"]
37 37
38[[bin]] 38[[bin]]
39name = "tl_mbox_mac_2" 39name = "mac_ffd"
40required-features = ["mac"] 40required-features = ["mac"]
41 41
42[[bin]] 42[[bin]]
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}
diff --git a/examples/stm32wb/src/bin/tl_mbox_mac_2.rs b/examples/stm32wb/src/bin/mac_rfd.rs
index e069adf87..938fe754f 100644
--- a/examples/stm32wb/src/bin/tl_mbox_mac_2.rs
+++ b/examples/stm32wb/src/bin/mac_rfd.rs
@@ -6,7 +6,8 @@ use defmt::*;
6use embassy_executor::Spawner; 6use embassy_executor::Spawner;
7use embassy_stm32::bind_interrupts; 7use embassy_stm32::bind_interrupts;
8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; 8use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
9use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, MacAddress, ResetRequest, SetRequest}; 9use embassy_stm32_wpan::sub::mac::commands::{AssociateRequest, ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::sub::mac::typedefs::{AddressMode, MacAddress, PibId};
10use embassy_stm32_wpan::sub::mm; 11use embassy_stm32_wpan::sub::mm;
11use embassy_stm32_wpan::TlMbox; 12use embassy_stm32_wpan::TlMbox;
12use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
@@ -71,46 +72,44 @@ async fn main(spawner: Spawner) {
71 info!("{}", response); 72 info!("{}", response);
72 73
73 info!("setting extended address"); 74 info!("setting extended address");
74 let extended_address: u64 = 0xACDE480000000001; 75 let extended_address: u64 = 0xACDE480000000002;
75 defmt::debug!("{}", &extended_address as *const _ as *const u8);
76 let response = mbox 76 let response = mbox
77 .mac_subsystem 77 .mac_subsystem
78 .send_command(SetRequest { 78 .send_command(SetRequest {
79 pib_attribute_ptr: &extended_address as *const _ as *const u8, 79 pib_attribute_ptr: &extended_address as *const _ as *const u8,
80 pib_attribute: 0x6F, 80 pib_attribute: PibId::ExtendedAddress,
81 stuffing: [0; 3],
82 }) 81 })
83 .await; 82 .await;
84 info!("{}", response); 83 info!("{}", response);
85 84
86 // info!("association request"); 85 info!("assocation request");
87 // mbox.mac_subsystem 86 let response = mbox
88 // .send_command(AssociateRequest { 87 .mac_subsystem
89 // channel_number: 16, 88 .send_command(AssociateRequest {
90 // channel_page: 0, 89 channel_number: 16,
91 // coord_addr_mode: 2, 90 channel_page: 0,
92 // coord_address: MacAddress { short: [0x22, 0x11] }, 91 coord_addr_mode: AddressMode::Short,
93 // capability_information: 0x80, 92 coord_address: MacAddress { short: [0x22, 0x11] },
94 // coord_pan_id: [0xAA, 0x1A], 93 capability_information: 0x80,
95 // security_level: 0, 94 coord_pan_id: [0xAA, 0x1A],
96 95 security_level: 0x00,
97 // key_id_mode: 0, 96 key_id_mode: 0,
98 // key_index: 0, 97 key_source: [0; 8],
99 // key_source: [0; 8], 98 key_index: 0,
100 // }) 99 })
101 // .await; 100 .await;
102 // info!("reading"); 101 info!("{}", response);
103 // let result = mbox.mac_subsystem.read().await; 102
104 // info!("{}", result.payload()); 103 info!("setting short address");
105 104 let short: u64 = 0xACDE480000000002;
106 // 105 let response = mbox
107 // info!("starting ble..."); 106 .mac_subsystem
108 // mbox.ble_subsystem.t_write(0x0c, &[]).await; 107 .send_command(SetRequest {
109 // 108 pib_attribute_ptr: &short as *const _ as *const u8,
110 // info!("waiting for ble..."); 109 pib_attribute: PibId::ShortAddress,
111 // let ble_event = mbox.ble_subsystem.tl_read().await; 110 })
112 // 111 .await;
113 // info!("ble event: {}", ble_event.payload()); 112 info!("{}", response);
114 113
115 info!("Test OK"); 114 info!("Test OK");
116 cortex_m::asm::bkpt(); 115 cortex_m::asm::bkpt();