1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#![no_std]
#![no_main]
use defmt::*;
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler};
use embassy_stm32::rcc::WPAN_DEFAULT;
use embassy_stm32_wpan::TlMbox;
use embassy_stm32_wpan::mac::commands::{AssociateRequest, DataRequest, GetRequest, ResetRequest, SetRequest};
use embassy_stm32_wpan::mac::event::MacEvent;
use embassy_stm32_wpan::mac::typedefs::{
AddressMode, Capabilities, KeyIdMode, MacAddress, MacChannel, PanId, PibId, SecurityLevel,
};
use embassy_stm32_wpan::sub::mm;
use {defmt_rtt as _, panic_probe as _};
bind_interrupts!(struct Irqs{
IPCC_C1_RX => ReceiveInterruptHandler;
IPCC_C1_TX => TransmitInterruptHandler;
});
#[embassy_executor::task]
async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) {
memory_manager.run_queue().await;
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
/*
How to make this work:
- Obtain a NUCLEO-STM32WB55 from your preferred supplier.
- Download and Install STM32CubeProgrammer.
- Download stm32wb5x_FUS_fw.bin, stm32wb5x_BLE_Mac_802_15_4_fw.bin, and Release_Notes.html from
gh:STMicroelectronics/STM32CubeWB@2234d97/Projects/STM32WB_Copro_Wireless_Binaries/STM32WB5x
- Open STM32CubeProgrammer
- On the right-hand pane, click "firmware upgrade" to upgrade the st-link firmware.
- Once complete, click connect to connect to the device.
- On the left hand pane, click the RSS signal icon to open "Firmware Upgrade Services".
- In the Release_Notes.html, find the memory address that corresponds to your device for the stm32wb5x_FUS_fw.bin file
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
- Once complete, in the Release_Notes.html, find the memory address that corresponds to your device for the
stm32wb5x_BLE_Mac_802_15_4_fw.bin file. It should not be the same memory address.
- Select that file, the memory address, "verify download", and then "Firmware Upgrade".
- Select "Start Wireless Stack".
- Disconnect from the device.
- Run this example.
Note: extended stack versions are not supported at this time. Do not attempt to install a stack with "extended" in the name.
*/
let mut config = embassy_stm32::Config::default();
config.rcc = WPAN_DEFAULT;
let p = embassy_stm32::init(config);
info!("Hello World!");
let config = Config::default();
let mbox = TlMbox::init(p.IPCC, Irqs, config).await;
let mut sys = mbox.sys_subsystem;
spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap());
let result = sys.shci_c2_mac_802_15_4_init().await;
info!("initialized mac: {}", result);
let (mut mac_rx, mut mac_tx) = mbox.mac_subsystem.split();
info!("resetting");
mac_tx
.send_command(&ResetRequest {
set_default_pib: true,
..Default::default()
})
.await
.unwrap();
defmt::info!("{:#x}", mac_rx.read().await.unwrap());
info!("setting extended address");
let extended_address: u64 = 0xACDE480000000002;
mac_tx
.send_command(&SetRequest {
pib_attribute_ptr: &extended_address as *const _ as *const u8,
pib_attribute: PibId::ExtendedAddress,
})
.await
.unwrap();
defmt::info!("{:#x}", mac_rx.read().await.unwrap());
info!("getting extended address");
mac_tx
.send_command(&GetRequest {
pib_attribute: PibId::ExtendedAddress,
..Default::default()
})
.await
.unwrap();
{
let evt = mac_rx.read().await.unwrap();
info!("{:#x}", evt);
if let MacEvent::MlmeGetCnf(evt) = evt {
if evt.pib_attribute_value_len == 8 {
let value = unsafe { core::ptr::read_unaligned(evt.pib_attribute_value_ptr as *const u64) };
info!("value {:#x}", value)
}
}
}
info!("assocation request");
let a = AssociateRequest {
channel_number: MacChannel::Channel16,
channel_page: 0,
coord_addr_mode: AddressMode::Short,
coord_address: MacAddress { short: [34, 17] },
capability_information: Capabilities::ALLOCATE_ADDRESS,
coord_pan_id: PanId([0x1A, 0xAA]),
security_level: SecurityLevel::Unsecure,
key_id_mode: KeyIdMode::Implicite,
key_source: [0; 8],
key_index: 152,
};
info!("{}", a);
mac_tx.send_command(&a).await.unwrap();
let short_addr = {
let evt = mac_rx.read().await.unwrap();
info!("{:#x}", evt);
if let MacEvent::MlmeAssociateCnf(conf) = evt {
conf.assoc_short_address
} else {
defmt::panic!()
}
};
info!("setting short address");
mac_tx
.send_command(&SetRequest {
pib_attribute_ptr: &short_addr as *const _ as *const u8,
pib_attribute: PibId::ShortAddress,
})
.await
.unwrap();
{
let evt = mac_rx.read().await.unwrap();
info!("{:#x}", evt);
}
info!("sending data");
let data = b"Hello from embassy!";
mac_tx
.send_command(
DataRequest {
src_addr_mode: AddressMode::Short,
dst_addr_mode: AddressMode::Short,
dst_pan_id: PanId([0x1A, 0xAA]),
dst_address: MacAddress::BROADCAST,
msdu_handle: 0x02,
ack_tx: 0x00,
gts_tx: false,
security_level: SecurityLevel::Unsecure,
..Default::default()
}
.set_buffer(data),
)
.await
.unwrap();
{
let evt = mac_rx.read().await.unwrap();
info!("{:#x}", evt);
}
loop {
match mac_rx.read().await {
Ok(evt) => info!("{:#x}", evt),
_ => continue,
};
}
}
|