aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32wb/.cargo/config.toml2
-rw-r--r--examples/stm32wb/Cargo.toml6
-rw-r--r--examples/stm32wb/src/bin/eddystone_beacon.rs2
-rw-r--r--examples/stm32wb/src/bin/gatt_server.rs2
-rw-r--r--examples/stm32wb/src/bin/mac_ffd.rs183
-rw-r--r--examples/stm32wb/src/bin/mac_rfd.rs170
-rw-r--r--examples/stm32wb/src/bin/tl_mbox_ble.rs2
7 files changed, 362 insertions, 5 deletions
diff --git a/examples/stm32wb/.cargo/config.toml b/examples/stm32wb/.cargo/config.toml
index 8b6d6d754..51c499ee7 100644
--- a/examples/stm32wb/.cargo/config.toml
+++ b/examples/stm32wb/.cargo/config.toml
@@ -1,6 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))'] 1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32WB55CCUx with your chip as listed in `probe-rs chip list` 2# replace STM32WB55CCUx with your chip as listed in `probe-rs chip list`
3# runner = "probe-rs run --chip STM32WB55RGVx --speed 1000 --connect-under-reset" 3# runner = "probe-run --chip STM32WB55RGVx --speed 1000 --connect-under-reset"
4runner = "teleprobe local run --chip STM32WB55RG --elf" 4runner = "teleprobe local run --chip STM32WB55RG --elf"
5 5
6[build] 6[build]
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml
index d8d5f0ec7..becf2d3fb 100644
--- a/examples/stm32wb/Cargo.toml
+++ b/examples/stm32wb/Cargo.toml
@@ -23,7 +23,7 @@ heapless = { version = "0.7.5", default-features = false }
23 23
24 24
25[features] 25[features]
26default = ["ble"] 26default = ["ble", "mac"]
27mac = ["embassy-stm32-wpan/mac"] 27mac = ["embassy-stm32-wpan/mac"]
28ble = ["embassy-stm32-wpan/ble"] 28ble = ["embassy-stm32-wpan/ble"]
29 29
@@ -36,6 +36,10 @@ name = "tl_mbox_mac"
36required-features = ["mac"] 36required-features = ["mac"]
37 37
38[[bin]] 38[[bin]]
39name = "mac_ffd"
40required-features = ["mac"]
41
42[[bin]]
39name = "eddystone_beacon" 43name = "eddystone_beacon"
40required-features = ["ble"] 44required-features = ["ble"]
41 45
diff --git a/examples/stm32wb/src/bin/eddystone_beacon.rs b/examples/stm32wb/src/bin/eddystone_beacon.rs
index b99f8cb2e..451bd7d29 100644
--- a/examples/stm32wb/src/bin/eddystone_beacon.rs
+++ b/examples/stm32wb/src/bin/eddystone_beacon.rs
@@ -63,7 +63,7 @@ async fn main(_spawner: Spawner) {
63 let sys_event = mbox.sys_subsystem.read().await; 63 let sys_event = mbox.sys_subsystem.read().await;
64 info!("sys event: {}", sys_event.payload()); 64 info!("sys event: {}", sys_event.payload());
65 65
66 mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; 66 let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
67 67
68 info!("resetting BLE..."); 68 info!("resetting BLE...");
69 mbox.ble_subsystem.reset().await; 69 mbox.ble_subsystem.reset().await;
diff --git a/examples/stm32wb/src/bin/gatt_server.rs b/examples/stm32wb/src/bin/gatt_server.rs
index 7621efb11..0f6419d45 100644
--- a/examples/stm32wb/src/bin/gatt_server.rs
+++ b/examples/stm32wb/src/bin/gatt_server.rs
@@ -71,7 +71,7 @@ async fn main(_spawner: Spawner) {
71 let sys_event = mbox.sys_subsystem.read().await; 71 let sys_event = mbox.sys_subsystem.read().await;
72 info!("sys event: {}", sys_event.payload()); 72 info!("sys event: {}", sys_event.payload());
73 73
74 mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; 74 let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
75 75
76 info!("resetting BLE..."); 76 info!("resetting BLE...");
77 mbox.ble_subsystem.reset().await; 77 mbox.ble_subsystem.reset().await;
diff --git a/examples/stm32wb/src/bin/mac_ffd.rs b/examples/stm32wb/src/bin/mac_ffd.rs
new file mode 100644
index 000000000..689a28353
--- /dev/null
+++ b/examples/stm32wb/src/bin/mac_ffd.rs
@@ -0,0 +1,183 @@
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::{AssociateResponse, ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::sub::mac::event::MacEvent;
11use embassy_stm32_wpan::sub::mac::typedefs::{MacChannel, MacStatus, PanId, PibId, SecurityLevel};
12use embassy_stm32_wpan::sub::mm;
13use embassy_stm32_wpan::TlMbox;
14use {defmt_rtt as _, panic_probe as _};
15
16bind_interrupts!(struct Irqs{
17 IPCC_C1_RX => ReceiveInterruptHandler;
18 IPCC_C1_TX => TransmitInterruptHandler;
19});
20
21#[embassy_executor::task]
22async fn run_mm_queue(memory_manager: mm::MemoryManager) {
23 memory_manager.run_queue().await;
24}
25
26#[embassy_executor::main]
27async fn main(spawner: Spawner) {
28 /*
29 How to make this work:
30
31 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
32 - Download and Install STM32CubeProgrammer.
33 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
34 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
35 - Open STM32CubeProgrammer
36 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
37 - Once complete, click connect to connect to the device.
38 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
39 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
40 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
41 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
42 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
43 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
44 - Select "Start Wireless Stack".
45 - Disconnect from the device.
46 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
47 - Run this example.
48
49 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
50 */
51
52 let p = embassy_stm32::init(Default::default());
53 info!("Hello World!");
54
55 let config = Config::default();
56 let mbox = TlMbox::init(p.IPCC, Irqs, config);
57
58 spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
59
60 let sys_event = mbox.sys_subsystem.read().await;
61 info!("sys event: {}", sys_event.payload());
62
63 core::mem::drop(sys_event);
64
65 let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
66 info!("initialized mac: {}", result);
67
68 info!("resetting");
69 mbox.mac_subsystem
70 .send_command(&ResetRequest { set_default_pib: true })
71 .await
72 .unwrap();
73 let evt = mbox.mac_subsystem.read().await;
74 defmt::info!("{:#x}", evt);
75
76 info!("setting extended address");
77 let extended_address: u64 = 0xACDE480000000001;
78 mbox.mac_subsystem
79 .send_command(&SetRequest {
80 pib_attribute_ptr: &extended_address as *const _ as *const u8,
81 pib_attribute: PibId::ExtendedAddress,
82 })
83 .await
84 .unwrap();
85 let evt = mbox.mac_subsystem.read().await;
86 defmt::info!("{:#x}", evt);
87
88 info!("setting short address");
89 let short_address: u16 = 0x1122;
90 mbox.mac_subsystem
91 .send_command(&SetRequest {
92 pib_attribute_ptr: &short_address as *const _ as *const u8,
93 pib_attribute: PibId::ShortAddress,
94 })
95 .await
96 .unwrap();
97 let evt = mbox.mac_subsystem.read().await;
98 defmt::info!("{:#x}", evt);
99
100 info!("setting association permit");
101 let association_permit: bool = true;
102 mbox.mac_subsystem
103 .send_command(&SetRequest {
104 pib_attribute_ptr: &association_permit as *const _ as *const u8,
105 pib_attribute: PibId::AssociationPermit,
106 })
107 .await
108 .unwrap();
109 let evt = mbox.mac_subsystem.read().await;
110 defmt::info!("{:#x}", evt);
111
112 info!("setting TX power");
113 let transmit_power: i8 = 2;
114 mbox.mac_subsystem
115 .send_command(&SetRequest {
116 pib_attribute_ptr: &transmit_power as *const _ as *const u8,
117 pib_attribute: PibId::TransmitPower,
118 })
119 .await
120 .unwrap();
121 let evt = mbox.mac_subsystem.read().await;
122 defmt::info!("{:#x}", evt);
123
124 info!("starting FFD device");
125 mbox.mac_subsystem
126 .send_command(&StartRequest {
127 pan_id: PanId([0x1A, 0xAA]),
128 channel_number: MacChannel::Channel16,
129 beacon_order: 0x0F,
130 superframe_order: 0x0F,
131 pan_coordinator: true,
132 battery_life_extension: false,
133 ..Default::default()
134 })
135 .await
136 .unwrap();
137 let evt = mbox.mac_subsystem.read().await;
138 defmt::info!("{:#x}", evt);
139
140 info!("setting RX on when idle");
141 let rx_on_while_idle: bool = true;
142 mbox.mac_subsystem
143 .send_command(&SetRequest {
144 pib_attribute_ptr: &rx_on_while_idle as *const _ as *const u8,
145 pib_attribute: PibId::RxOnWhenIdle,
146 })
147 .await
148 .unwrap();
149 let evt = mbox.mac_subsystem.read().await;
150 defmt::info!("{:#x}", evt);
151
152 loop {
153 let evt = mbox.mac_subsystem.read().await;
154 defmt::info!("{:#x}", evt);
155
156 if let Ok(evt) = evt {
157 match evt {
158 MacEvent::MlmeAssociateInd(association) => mbox
159 .mac_subsystem
160 .send_command(&AssociateResponse {
161 device_address: association.device_address,
162 assoc_short_address: [0x33, 0x44],
163 status: MacStatus::Success,
164 security_level: SecurityLevel::Unsecure,
165 ..Default::default()
166 })
167 .await
168 .unwrap(),
169 MacEvent::McpsDataInd(data_ind) => {
170 let data_addr = data_ind.msdu_ptr;
171 let mut data = [0u8; 256];
172 unsafe { data_addr.copy_to(&mut data as *mut _, data_ind.msdu_length as usize) }
173 info!("{}", data[..data_ind.msdu_length as usize]);
174
175 if &data[..data_ind.msdu_length as usize] == b"Hello from embassy!" {
176 info!("success");
177 }
178 }
179 _ => {}
180 }
181 }
182 }
183}
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs
new file mode 100644
index 000000000..ea349f9a8
--- /dev/null
+++ b/examples/stm32wb/src/bin/mac_rfd.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::sub::mac::commands::{AssociateRequest, DataRequest, GetRequest, ResetRequest, SetRequest};
10use embassy_stm32_wpan::sub::mac::event::MacEvent;
11use embassy_stm32_wpan::sub::mac::typedefs::{
12 AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel,
13};
14use embassy_stm32_wpan::sub::mm;
15use embassy_stm32_wpan::TlMbox;
16use {defmt_rtt as _, panic_probe as _};
17
18bind_interrupts!(struct Irqs{
19 IPCC_C1_RX => ReceiveInterruptHandler;
20 IPCC_C1_TX => TransmitInterruptHandler;
21});
22
23#[embassy_executor::task]
24async fn run_mm_queue(memory_manager: mm::MemoryManager) {
25 memory_manager.run_queue().await;
26}
27
28#[embassy_executor::main]
29async fn main(spawner: Spawner) {
30 /*
31 How to make this work:
32
33 - Obtain a NUCLEO-STM32WB55 from your preferred supplier.
34 - Download and Install STM32CubeProgrammer.
35 - Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Stack_full_fw.bin, and Release_Notes.html from
36 gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
37 - Open STM32CubeProgrammer
38 - On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
39 - Once complete, click connect to connect to the device.
40 - On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
41 - In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
42 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
43 - Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
44 stm32wb5x_BLE_Stack_full_fw.bin file. It should not be the same memory address.
45 - Select that file, the memory address, "verify download", and then "Firmware Upgrade".
46 - Select "Start Wireless Stack".
47 - Disconnect from the device.
48 - In the examples folder for stm32wb, modify the memory.x file to match your target device.
49 - Run this example.
50
51 Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
52 */
53
54 let p = embassy_stm32::init(Default::default());
55 info!("Hello World!");
56
57 let config = Config::default();
58 let mbox = TlMbox::init(p.IPCC, Irqs, config);
59
60 spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap();
61
62 let sys_event = mbox.sys_subsystem.read().await;
63 info!("sys event: {}", sys_event.payload());
64
65 core::mem::drop(sys_event);
66
67 let result = mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await;
68 info!("initialized mac: {}", result);
69
70 info!("resetting");
71 mbox.mac_subsystem
72 .send_command(&ResetRequest { set_default_pib: true })
73 .await
74 .unwrap();
75 let evt = mbox.mac_subsystem.read().await;
76 info!("{:#x}", evt);
77
78 info!("setting extended address");
79 let extended_address: u64 = 0xACDE480000000002;
80 mbox.mac_subsystem
81 .send_command(&SetRequest {
82 pib_attribute_ptr: &extended_address as *const _ as *const u8,
83 pib_attribute: PibId::ExtendedAddress,
84 })
85 .await
86 .unwrap();
87 let evt = mbox.mac_subsystem.read().await;
88 info!("{:#x}", evt);
89
90 info!("getting extended address");
91 mbox.mac_subsystem
92 .send_command(&GetRequest {
93 pib_attribute: PibId::ExtendedAddress,
94 })
95 .await
96 .unwrap();
97 let evt = mbox.mac_subsystem.read().await;
98 info!("{:#x}", evt);
99
100 if let Ok(MacEvent::MlmeGetCnf(evt)) = evt {
101 if evt.pib_attribute_value_len == 8 {
102 let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
103
104 info!("value {:#x}", value)
105 }
106 }
107
108 info!("assocation request");
109 let a = AssociateRequest {
110 channel_number: MacChannel::Channel16,
111 channel_page: 0,
112 coord_addr_mode: AddressMode::Short,
113 coord_address: MacAddress { short: [34, 17] },
114 capability_information: Capabilities::ALLOCATE_ADDRESS,
115 coord_pan_id: PanId([0x1A, 0xAA]),
116 security_level: SecurityLevel::Unsecure,
117 key_id_mode: KeyIdMode::Implicite,
118 key_source: [0; 8],
119 key_index: 152,
120 };
121 info!("{}", a);
122 mbox.mac_subsystem.send_command(&a).await.unwrap();
123 let evt = mbox.mac_subsystem.read().await;
124 info!("{:#x}", evt);
125
126 let short_addr = if let Ok(MacEvent::MlmeAssociateCnf(conf)) = evt {
127 conf.assoc_short_address
128 } else {
129 defmt::panic!()
130 };
131
132 info!("setting short address");
133 mbox.mac_subsystem
134 .send_command(&SetRequest {
135 pib_attribute_ptr: &short_addr as *const _ as *const u8,
136 pib_attribute: PibId::ShortAddress,
137 })
138 .await
139 .unwrap();
140 let evt = mbox.mac_subsystem.read().await;
141 info!("{:#x}", evt);
142
143 info!("sending data");
144 let mut data_buffer = [0u8; 256];
145 let data = b"Hello from embassy!";
146 data_buffer[..data.len()].copy_from_slice(data);
147 mbox.mac_subsystem
148 .send_command(&DataRequest {
149 src_addr_mode: AddressMode::Short,
150 dst_addr_mode: AddressMode::Short,
151 dst_pan_id: PanId([0x1A, 0xAA]),
152 dst_address: MacAddress::BROADCAST,
153 msdu_handle: 0x02,
154 ack_tx: 0x00,
155 gts_tx: false,
156 msdu_ptr: &data_buffer as *const _ as *const u8,
157 msdu_length: data.len() as u8,
158 security_level: SecurityLevel::Unsecure,
159 ..Default::default()
160 })
161 .await
162 .unwrap();
163 let evt = mbox.mac_subsystem.read().await;
164 info!("{:#x}", evt);
165
166 loop {
167 let evt = mbox.mac_subsystem.read().await;
168 info!("{:#x}", evt);
169 }
170}
diff --git a/examples/stm32wb/src/bin/tl_mbox_ble.rs b/examples/stm32wb/src/bin/tl_mbox_ble.rs
index a511e89aa..90349422e 100644
--- a/examples/stm32wb/src/bin/tl_mbox_ble.rs
+++ b/examples/stm32wb/src/bin/tl_mbox_ble.rs
@@ -49,7 +49,7 @@ async fn main(_spawner: Spawner) {
49 let sys_event = mbox.sys_subsystem.read().await; 49 let sys_event = mbox.sys_subsystem.read().await;
50 info!("sys event: {}", sys_event.payload()); 50 info!("sys event: {}", sys_event.payload());
51 51
52 mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; 52 let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await;
53 53
54 info!("starting ble..."); 54 info!("starting ble...");
55 mbox.ble_subsystem.tl_write(0x0c, &[]).await; 55 mbox.ble_subsystem.tl_write(0x0c, &[]).await;