aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32wb/src/bin/mac_rfd.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_rfd.rs
parent4aca7c8811b70e420280893784cdad2acbe326f9 (diff)
wip: added MAC commands
Diffstat (limited to 'examples/stm32wb/src/bin/mac_rfd.rs')
-rw-r--r--examples/stm32wb/src/bin/mac_rfd.rs116
1 files changed, 116 insertions, 0 deletions
diff --git a/examples/stm32wb/src/bin/mac_rfd.rs b/examples/stm32wb/src/bin/mac_rfd.rs
new file mode 100644
index 000000000..938fe754f
--- /dev/null
+++ b/examples/stm32wb/src/bin/mac_rfd.rs
@@ -0,0 +1,116 @@
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, ResetRequest, SetRequest, StartRequest};
10use embassy_stm32_wpan::sub::mac::typedefs::{AddressMode, MacAddress, 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 = 0xACDE480000000002;
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!("assocation request");
86 let response = mbox
87 .mac_subsystem
88 .send_command(AssociateRequest {
89 channel_number: 16,
90 channel_page: 0,
91 coord_addr_mode: AddressMode::Short,
92 coord_address: MacAddress { short: [0x22, 0x11] },
93 capability_information: 0x80,
94 coord_pan_id: [0xAA, 0x1A],
95 security_level: 0x00,
96 key_id_mode: 0,
97 key_source: [0; 8],
98 key_index: 0,
99 })
100 .await;
101 info!("{}", response);
102
103 info!("setting short address");
104 let short: u64 = 0xACDE480000000002;
105 let response = mbox
106 .mac_subsystem
107 .send_command(SetRequest {
108 pib_attribute_ptr: &short as *const _ as *const u8,
109 pib_attribute: PibId::ShortAddress,
110 })
111 .await;
112 info!("{}", response);
113
114 info!("Test OK");
115 cortex_m::asm::bkpt();
116}