diff options
| author | xoviat <[email protected]> | 2023-06-22 21:05:51 -0500 |
|---|---|---|
| committer | xoviat <[email protected]> | 2023-06-22 21:05:51 -0500 |
| commit | caf63b9e7336ed3ddb0dc997d431f15a26ae7693 (patch) | |
| tree | 2d0543c64c50c749f95552b2db23a82b80d20f87 | |
| parent | 64ff1a6b75aa13797cf64bb97e597f333a2ae9b6 (diff) | |
stm32/tests: update ble test
| -rw-r--r-- | embassy-stm32-wpan/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32wb/Cargo.toml | 5 | ||||
| -rw-r--r-- | examples/stm32wb/src/bin/tl_mbox_mac.rs | 2 | ||||
| -rw-r--r-- | tests/stm32/Cargo.toml | 3 | ||||
| -rw-r--r-- | tests/stm32/src/bin/tl_mbox.rs | 221 |
5 files changed, 207 insertions, 26 deletions
diff --git a/embassy-stm32-wpan/Cargo.toml b/embassy-stm32-wpan/Cargo.toml index ee60a22e5..6d78ca577 100644 --- a/embassy-stm32-wpan/Cargo.toml +++ b/embassy-stm32-wpan/Cargo.toml | |||
| @@ -24,7 +24,7 @@ heapless = "0.7.16" | |||
| 24 | 24 | ||
| 25 | bit_field = "0.10.2" | 25 | bit_field = "0.10.2" |
| 26 | stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] } | 26 | stm32-device-signature = { version = "0.3.3", features = ["stm32wb5x"] } |
| 27 | stm32wb-hci = { version = "*", git = "https://github.com/OueslatiGhaith/stm32wb-hci", features = ["version-5-0"], optional = true } | 27 | stm32wb-hci = { version = "0.1.2", features = ["version-5-0"], optional = true } |
| 28 | 28 | ||
| 29 | [features] | 29 | [features] |
| 30 | defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt"] | 30 | defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt"] |
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index 726cd10d4..fbb2d918b 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml | |||
| @@ -37,4 +37,7 @@ required-features = ["mac"] | |||
| 37 | 37 | ||
| 38 | [[bin]] | 38 | [[bin]] |
| 39 | name = "eddystone_beacon" | 39 | name = "eddystone_beacon" |
| 40 | required-features = ["ble"] \ No newline at end of file | 40 | required-features = ["ble"] |
| 41 | |||
| 42 | [patch.crates-io] | ||
| 43 | stm32wb-hci = { git = "https://github.com/OueslatiGhaith/stm32wb-hci", rev = "9f663be"} \ No newline at end of file | ||
diff --git a/examples/stm32wb/src/bin/tl_mbox_mac.rs b/examples/stm32wb/src/bin/tl_mbox_mac.rs index 6c8653cf4..afd319a41 100644 --- a/examples/stm32wb/src/bin/tl_mbox_mac.rs +++ b/examples/stm32wb/src/bin/tl_mbox_mac.rs | |||
| @@ -46,7 +46,7 @@ async fn main(_spawner: Spawner) { | |||
| 46 | let config = Config::default(); | 46 | let config = Config::default(); |
| 47 | let mbox = TlMbox::init(p.IPCC, Irqs, config); | 47 | let mbox = TlMbox::init(p.IPCC, Irqs, config); |
| 48 | 48 | ||
| 49 | let sys_event = mbox.sys_subsystem.tl_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_mac_802_15_4_init().await; | 52 | mbox.sys_subsystem.shci_c2_mac_802_15_4_init().await; |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index fe646927a..c2422f7bc 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -46,6 +46,9 @@ rand_chacha = { version = "0.3", default-features = false } | |||
| 46 | 46 | ||
| 47 | chrono = { version = "^0.4", default-features = false, optional = true} | 47 | chrono = { version = "^0.4", default-features = false, optional = true} |
| 48 | 48 | ||
| 49 | [patch.crates-io] | ||
| 50 | stm32wb-hci = { git = "https://github.com/OueslatiGhaith/stm32wb-hci", rev = "9f663be"} | ||
| 51 | |||
| 49 | # BEGIN TESTS | 52 | # BEGIN TESTS |
| 50 | # Generated by gen_test.py. DO NOT EDIT. | 53 | # Generated by gen_test.py. DO NOT EDIT. |
| 51 | [[bin]] | 54 | [[bin]] |
diff --git a/tests/stm32/src/bin/tl_mbox.rs b/tests/stm32/src/bin/tl_mbox.rs index f55c0292a..76c736a5b 100644 --- a/tests/stm32/src/bin/tl_mbox.rs +++ b/tests/stm32/src/bin/tl_mbox.rs | |||
| @@ -6,43 +6,49 @@ | |||
| 6 | #[path = "../common.rs"] | 6 | #[path = "../common.rs"] |
| 7 | mod common; | 7 | mod common; |
| 8 | 8 | ||
| 9 | use core::mem; | 9 | use core::time::Duration; |
| 10 | 10 | ||
| 11 | use common::*; | 11 | use common::*; |
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_futures::poll_once; | ||
| 14 | use embassy_stm32::bind_interrupts; | 13 | use embassy_stm32::bind_interrupts; |
| 15 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | 14 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 15 | use embassy_stm32_wpan::ble::hci::host::uart::UartHci; | ||
| 16 | use embassy_stm32_wpan::ble::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; | ||
| 17 | use embassy_stm32_wpan::ble::hci::types::AdvertisingType; | ||
| 18 | use embassy_stm32_wpan::ble::hci::vendor::stm32wb::command::gap::{ | ||
| 19 | AdvertisingDataType, DiscoverableParameters, GapCommands, Role, | ||
| 20 | }; | ||
| 21 | use embassy_stm32_wpan::ble::hci::vendor::stm32wb::command::gatt::GattCommands; | ||
| 22 | use embassy_stm32_wpan::ble::hci::vendor::stm32wb::command::hal::{ConfigData, HalCommands, PowerLevel}; | ||
| 23 | use embassy_stm32_wpan::ble::hci::BdAddr; | ||
| 24 | use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp; | ||
| 16 | use embassy_stm32_wpan::{mm, TlMbox}; | 25 | use embassy_stm32_wpan::{mm, TlMbox}; |
| 17 | use embassy_time::{Duration, Timer}; | 26 | use {defmt_rtt as _, panic_probe as _}; |
| 18 | 27 | ||
| 19 | bind_interrupts!(struct Irqs{ | 28 | bind_interrupts!(struct Irqs{ |
| 20 | IPCC_C1_RX => ReceiveInterruptHandler; | 29 | IPCC_C1_RX => ReceiveInterruptHandler; |
| 21 | IPCC_C1_TX => TransmitInterruptHandler; | 30 | IPCC_C1_TX => TransmitInterruptHandler; |
| 22 | }); | 31 | }); |
| 23 | 32 | ||
| 33 | const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7; | ||
| 34 | |||
| 24 | #[embassy_executor::task] | 35 | #[embassy_executor::task] |
| 25 | async fn run_mm_queue(memory_manager: mm::MemoryManager) { | 36 | async fn run_mm_queue(memory_manager: mm::MemoryManager) { |
| 26 | memory_manager.run_queue().await; | 37 | memory_manager.run_queue().await; |
| 27 | } | 38 | } |
| 28 | 39 | ||
| 29 | #[embassy_executor::main] | 40 | #[embassy_executor::main] |
| 30 | async fn main(spawner: Spawner) { | 41 | async fn main(_spawner: Spawner) { |
| 31 | let p = embassy_stm32::init(config()); | 42 | let p = embassy_stm32::init(config()); |
| 32 | info!("Hello World!"); | 43 | info!("Hello World!"); |
| 33 | 44 | ||
| 34 | let config = Config::default(); | 45 | let config = Config::default(); |
| 35 | let mbox = TlMbox::init(p.IPCC, Irqs, config); | 46 | let mut mbox = TlMbox::init(p.IPCC, Irqs, config); |
| 36 | |||
| 37 | spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap(); | ||
| 38 | |||
| 39 | let ready_event = mbox.sys_subsystem.read().await; | ||
| 40 | let _ = poll_once(mbox.sys_subsystem.read()); // clear rx not | ||
| 41 | 47 | ||
| 42 | info!("sys event {:x} : {:x}", ready_event.stub().kind, ready_event.payload()); | 48 | // spawner.spawn(run_mm_queue(mbox.mm_subsystem)).unwrap(); |
| 43 | 49 | ||
| 44 | // test memory manager | 50 | let sys_event = mbox.sys_subsystem.read().await; |
| 45 | mem::drop(ready_event); | 51 | info!("sys event: {}", sys_event.payload()); |
| 46 | 52 | ||
| 47 | let fw_info = mbox.sys_subsystem.wireless_fw_info().unwrap(); | 53 | let fw_info = mbox.sys_subsystem.wireless_fw_info().unwrap(); |
| 48 | let version_major = fw_info.version_major(); | 54 | let version_major = fw_info.version_major(); |
| @@ -57,19 +63,188 @@ async fn main(spawner: Spawner) { | |||
| 57 | version_major, version_minor, subversion, sram2a_size, sram2b_size | 63 | version_major, version_minor, subversion, sram2a_size, sram2b_size |
| 58 | ); | 64 | ); |
| 59 | 65 | ||
| 60 | Timer::after(Duration::from_millis(50)).await; | 66 | mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; |
| 67 | |||
| 68 | info!("resetting BLE..."); | ||
| 69 | mbox.ble_subsystem.reset().await; | ||
| 70 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 71 | info!("{}", response); | ||
| 72 | |||
| 73 | info!("config public address..."); | ||
| 74 | mbox.ble_subsystem | ||
| 75 | .write_config_data(&ConfigData::public_address(get_bd_addr()).build()) | ||
| 76 | .await; | ||
| 77 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 78 | info!("{}", response); | ||
| 79 | |||
| 80 | info!("config random address..."); | ||
| 81 | mbox.ble_subsystem | ||
| 82 | .write_config_data(&ConfigData::random_address(get_random_addr()).build()) | ||
| 83 | .await; | ||
| 84 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 85 | info!("{}", response); | ||
| 86 | |||
| 87 | info!("config identity root..."); | ||
| 88 | mbox.ble_subsystem | ||
| 89 | .write_config_data(&ConfigData::identity_root(&get_irk()).build()) | ||
| 90 | .await; | ||
| 91 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 92 | info!("{}", response); | ||
| 93 | |||
| 94 | info!("config encryption root..."); | ||
| 95 | mbox.ble_subsystem | ||
| 96 | .write_config_data(&ConfigData::encryption_root(&get_erk()).build()) | ||
| 97 | .await; | ||
| 98 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 99 | info!("{}", response); | ||
| 100 | |||
| 101 | info!("config tx power level..."); | ||
| 102 | mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await; | ||
| 103 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 104 | info!("{}", response); | ||
| 105 | |||
| 106 | info!("GATT init..."); | ||
| 107 | mbox.ble_subsystem.init_gatt().await; | ||
| 108 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 109 | info!("{}", response); | ||
| 110 | |||
| 111 | info!("GAP init..."); | ||
| 112 | mbox.ble_subsystem | ||
| 113 | .init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH) | ||
| 114 | .await; | ||
| 115 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 116 | info!("{}", response); | ||
| 117 | |||
| 118 | // info!("set scan response..."); | ||
| 119 | // mbox.ble_subsystem.le_set_scan_response_data(&[]).await.unwrap(); | ||
| 120 | // let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 121 | // info!("{}", response); | ||
| 122 | |||
| 123 | info!("set discoverable..."); | ||
| 124 | mbox.ble_subsystem | ||
| 125 | .set_discoverable(&DiscoverableParameters { | ||
| 126 | advertising_type: AdvertisingType::NonConnectableUndirected, | ||
| 127 | advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))), | ||
| 128 | address_type: OwnAddressType::Public, | ||
| 129 | filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan, | ||
| 130 | local_name: None, | ||
| 131 | advertising_data: &[], | ||
| 132 | conn_interval: (None, None), | ||
| 133 | }) | ||
| 134 | .await | ||
| 135 | .unwrap(); | ||
| 136 | |||
| 137 | let response = mbox.ble_subsystem.read().await; | ||
| 138 | info!("{}", response); | ||
| 139 | |||
| 140 | // remove some advertisement to decrease the packet size | ||
| 141 | info!("delete tx power ad type..."); | ||
| 142 | mbox.ble_subsystem | ||
| 143 | .delete_ad_type(AdvertisingDataType::TxPowerLevel) | ||
| 144 | .await; | ||
| 145 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 146 | info!("{}", response); | ||
| 147 | |||
| 148 | info!("delete conn interval ad type..."); | ||
| 149 | mbox.ble_subsystem | ||
| 150 | .delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval) | ||
| 151 | .await; | ||
| 152 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 153 | info!("{}", response); | ||
| 154 | |||
| 155 | info!("update advertising data..."); | ||
| 156 | mbox.ble_subsystem | ||
| 157 | .update_advertising_data(&eddystone_advertising_data()) | ||
| 158 | .await | ||
| 159 | .unwrap(); | ||
| 160 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 161 | info!("{}", response); | ||
| 162 | |||
| 163 | info!("update advertising data type..."); | ||
| 164 | mbox.ble_subsystem | ||
| 165 | .update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe]) | ||
| 166 | .await | ||
| 167 | .unwrap(); | ||
| 168 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 169 | info!("{}", response); | ||
| 170 | |||
| 171 | info!("update advertising data flags..."); | ||
| 172 | mbox.ble_subsystem | ||
| 173 | .update_advertising_data(&[ | ||
| 174 | 2, | ||
| 175 | AdvertisingDataType::Flags as u8, | ||
| 176 | (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support | ||
| 177 | ]) | ||
| 178 | .await | ||
| 179 | .unwrap(); | ||
| 180 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 181 | info!("{}", response); | ||
| 182 | |||
| 183 | info!("Test OK"); | ||
| 184 | cortex_m::asm::bkpt(); | ||
| 185 | } | ||
| 186 | |||
| 187 | fn get_bd_addr() -> BdAddr { | ||
| 188 | let mut bytes = [0u8; 6]; | ||
| 61 | 189 | ||
| 62 | let result = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; | 190 | let lhci_info = LhciC1DeviceInformationCcrp::new(); |
| 63 | info!("subsystem initialization: {}", result); | 191 | bytes[0] = (lhci_info.uid64 & 0xff) as u8; |
| 192 | bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8; | ||
| 193 | bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8; | ||
| 194 | bytes[3] = lhci_info.device_type_id; | ||
| 195 | bytes[4] = (lhci_info.st_company_id & 0xff) as u8; | ||
| 196 | bytes[5] = (lhci_info.st_company_id >> 8 & 0xff) as u8; | ||
| 64 | 197 | ||
| 65 | info!("starting ble..."); | 198 | BdAddr(bytes) |
| 66 | mbox.ble_subsystem.tl_write(0x0c, &[]).await; | 199 | } |
| 67 | 200 | ||
| 68 | info!("waiting for ble..."); | 201 | fn get_random_addr() -> BdAddr { |
| 69 | let ble_event = mbox.ble_subsystem.tl_read().await; | 202 | let mut bytes = [0u8; 6]; |
| 70 | 203 | ||
| 71 | info!("ble event {:x} : {:x}", ble_event.stub().kind, ble_event.payload()); | 204 | let lhci_info = LhciC1DeviceInformationCcrp::new(); |
| 205 | bytes[0] = (lhci_info.uid64 & 0xff) as u8; | ||
| 206 | bytes[1] = ((lhci_info.uid64 >> 8) & 0xff) as u8; | ||
| 207 | bytes[2] = ((lhci_info.uid64 >> 16) & 0xff) as u8; | ||
| 208 | bytes[3] = 0; | ||
| 209 | bytes[4] = 0x6E; | ||
| 210 | bytes[5] = 0xED; | ||
| 72 | 211 | ||
| 73 | info!("Test OK"); | 212 | BdAddr(bytes) |
| 74 | cortex_m::asm::bkpt(); | 213 | } |
| 214 | |||
| 215 | const BLE_CFG_IRK: [u8; 16] = [ | ||
| 216 | 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, | ||
| 217 | ]; | ||
| 218 | const BLE_CFG_ERK: [u8; 16] = [ | ||
| 219 | 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, 0xfe, 0xdc, 0xba, 0x09, 0x87, 0x65, 0x43, 0x21, | ||
| 220 | ]; | ||
| 221 | |||
| 222 | fn get_irk() -> EncryptionKey { | ||
| 223 | EncryptionKey(BLE_CFG_IRK) | ||
| 224 | } | ||
| 225 | |||
| 226 | fn get_erk() -> EncryptionKey { | ||
| 227 | EncryptionKey(BLE_CFG_ERK) | ||
| 228 | } | ||
| 229 | |||
| 230 | fn eddystone_advertising_data() -> [u8; 24] { | ||
| 231 | const EDDYSTONE_URL: &[u8] = b"www.rust-lang.com"; | ||
| 232 | |||
| 233 | let mut service_data = [0u8; 24]; | ||
| 234 | let url_len = EDDYSTONE_URL.len(); | ||
| 235 | |||
| 236 | service_data[0] = 6 + url_len as u8; | ||
| 237 | service_data[1] = AdvertisingDataType::ServiceData as u8; | ||
| 238 | |||
| 239 | // 16-bit eddystone uuid | ||
| 240 | service_data[2] = 0xaa; | ||
| 241 | service_data[3] = 0xFE; | ||
| 242 | |||
| 243 | service_data[4] = 0x10; // URL frame type | ||
| 244 | service_data[5] = 22_i8 as u8; // calibrated TX power at 0m | ||
| 245 | service_data[6] = 0x03; // eddystone url prefix = https | ||
| 246 | |||
| 247 | service_data[7..(7 + url_len)].copy_from_slice(EDDYSTONE_URL); | ||
| 248 | |||
| 249 | service_data | ||
| 75 | } | 250 | } |
