diff options
Diffstat (limited to 'tests/stm32/src/bin/wpan_ble.rs')
| -rw-r--r-- | tests/stm32/src/bin/wpan_ble.rs | 124 |
1 files changed, 55 insertions, 69 deletions
diff --git a/tests/stm32/src/bin/wpan_ble.rs b/tests/stm32/src/bin/wpan_ble.rs index 8957bfc04..b4c0cbf56 100644 --- a/tests/stm32/src/bin/wpan_ble.rs +++ b/tests/stm32/src/bin/wpan_ble.rs | |||
| @@ -12,16 +12,16 @@ use embassy_executor::Spawner; | |||
| 12 | use embassy_stm32::bind_interrupts; | 12 | use embassy_stm32::bind_interrupts; |
| 13 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; | 13 | use embassy_stm32::ipcc::{Config, ReceiveInterruptHandler, TransmitInterruptHandler}; |
| 14 | use embassy_stm32::rcc::WPAN_DEFAULT; | 14 | use embassy_stm32::rcc::WPAN_DEFAULT; |
| 15 | use embassy_stm32_wpan::TlMbox; | ||
| 16 | use embassy_stm32_wpan::hci::BdAddr; | ||
| 15 | use embassy_stm32_wpan::hci::host::uart::UartHci; | 17 | use embassy_stm32_wpan::hci::host::uart::UartHci; |
| 16 | use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; | 18 | use embassy_stm32_wpan::hci::host::{AdvertisingFilterPolicy, EncryptionKey, HostHci, OwnAddressType}; |
| 17 | use embassy_stm32_wpan::hci::types::AdvertisingType; | 19 | use embassy_stm32_wpan::hci::types::AdvertisingType; |
| 18 | use embassy_stm32_wpan::hci::vendor::command::gap::{AdvertisingDataType, DiscoverableParameters, GapCommands, Role}; | 20 | use embassy_stm32_wpan::hci::vendor::command::gap::{AdvertisingDataType, DiscoverableParameters, GapCommands, Role}; |
| 19 | use embassy_stm32_wpan::hci::vendor::command::gatt::GattCommands; | 21 | use embassy_stm32_wpan::hci::vendor::command::gatt::GattCommands; |
| 20 | use embassy_stm32_wpan::hci::vendor::command::hal::{ConfigData, HalCommands, PowerLevel}; | 22 | use embassy_stm32_wpan::hci::vendor::command::hal::{ConfigData, HalCommands, PowerLevel}; |
| 21 | use embassy_stm32_wpan::hci::BdAddr; | ||
| 22 | use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp; | 23 | use embassy_stm32_wpan::lhci::LhciC1DeviceInformationCcrp; |
| 23 | use embassy_stm32_wpan::sub::mm; | 24 | use embassy_stm32_wpan::sub::mm; |
| 24 | use embassy_stm32_wpan::TlMbox; | ||
| 25 | use {defmt_rtt as _, panic_probe as _}; | 25 | use {defmt_rtt as _, panic_probe as _}; |
| 26 | 26 | ||
| 27 | bind_interrupts!(struct Irqs{ | 27 | bind_interrupts!(struct Irqs{ |
| @@ -32,7 +32,7 @@ bind_interrupts!(struct Irqs{ | |||
| 32 | const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7; | 32 | const BLE_GAP_DEVICE_NAME_LENGTH: u8 = 7; |
| 33 | 33 | ||
| 34 | #[embassy_executor::task] | 34 | #[embassy_executor::task] |
| 35 | async fn run_mm_queue(memory_manager: mm::MemoryManager) { | 35 | async fn run_mm_queue(mut memory_manager: mm::MemoryManager<'static>) { |
| 36 | memory_manager.run_queue().await; | 36 | memory_manager.run_queue().await; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| @@ -45,14 +45,13 @@ async fn main(spawner: Spawner) { | |||
| 45 | info!("Hello World!"); | 45 | info!("Hello World!"); |
| 46 | 46 | ||
| 47 | let config = Config::default(); | 47 | let config = Config::default(); |
| 48 | let mut mbox = TlMbox::init(p.IPCC, Irqs, config); | 48 | let mbox = TlMbox::init(p.IPCC, Irqs, config).await; |
| 49 | let mut sys = mbox.sys_subsystem; | ||
| 50 | let mut ble = mbox.ble_subsystem; | ||
| 49 | 51 | ||
| 50 | spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap()); | 52 | spawner.spawn(run_mm_queue(mbox.mm_subsystem).unwrap()); |
| 51 | 53 | ||
| 52 | let sys_event = mbox.sys_subsystem.read().await; | 54 | let fw_info = sys.wireless_fw_info().unwrap(); |
| 53 | info!("sys event: {}", sys_event.payload()); | ||
| 54 | |||
| 55 | let fw_info = mbox.sys_subsystem.wireless_fw_info().unwrap(); | ||
| 56 | let version_major = fw_info.version_major(); | 55 | let version_major = fw_info.version_major(); |
| 57 | let version_minor = fw_info.version_minor(); | 56 | let version_minor = fw_info.version_minor(); |
| 58 | let subversion = fw_info.subversion(); | 57 | let subversion = fw_info.subversion(); |
| @@ -65,121 +64,108 @@ async fn main(spawner: Spawner) { | |||
| 65 | version_major, version_minor, subversion, sram2a_size, sram2b_size | 64 | version_major, version_minor, subversion, sram2a_size, sram2b_size |
| 66 | ); | 65 | ); |
| 67 | 66 | ||
| 68 | let _ = mbox.sys_subsystem.shci_c2_ble_init(Default::default()).await; | 67 | let _ = sys.shci_c2_ble_init(Default::default()).await; |
| 69 | 68 | ||
| 70 | info!("resetting BLE..."); | 69 | info!("resetting BLE..."); |
| 71 | mbox.ble_subsystem.reset().await; | 70 | ble.reset().await; |
| 72 | let response = mbox.ble_subsystem.read().await.unwrap(); | 71 | let response = ble.read().await.unwrap(); |
| 73 | info!("{}", response); | 72 | info!("{}", response); |
| 74 | 73 | ||
| 75 | info!("config public address..."); | 74 | info!("config public address..."); |
| 76 | mbox.ble_subsystem | 75 | ble.write_config_data(&ConfigData::public_address(get_bd_addr()).build()) |
| 77 | .write_config_data(&ConfigData::public_address(get_bd_addr()).build()) | ||
| 78 | .await; | 76 | .await; |
| 79 | let response = mbox.ble_subsystem.read().await.unwrap(); | 77 | let response = ble.read().await.unwrap(); |
| 80 | info!("{}", response); | 78 | info!("{}", response); |
| 81 | 79 | ||
| 82 | info!("config random address..."); | 80 | info!("config random address..."); |
| 83 | mbox.ble_subsystem | 81 | ble.write_config_data(&ConfigData::random_address(get_random_addr()).build()) |
| 84 | .write_config_data(&ConfigData::random_address(get_random_addr()).build()) | ||
| 85 | .await; | 82 | .await; |
| 86 | let response = mbox.ble_subsystem.read().await.unwrap(); | 83 | let response = ble.read().await.unwrap(); |
| 87 | info!("{}", response); | 84 | info!("{}", response); |
| 88 | 85 | ||
| 89 | info!("config identity root..."); | 86 | info!("config identity root..."); |
| 90 | mbox.ble_subsystem | 87 | ble.write_config_data(&ConfigData::identity_root(&get_irk()).build()) |
| 91 | .write_config_data(&ConfigData::identity_root(&get_irk()).build()) | ||
| 92 | .await; | 88 | .await; |
| 93 | let response = mbox.ble_subsystem.read().await.unwrap(); | 89 | let response = ble.read().await.unwrap(); |
| 94 | info!("{}", response); | 90 | info!("{}", response); |
| 95 | 91 | ||
| 96 | info!("config encryption root..."); | 92 | info!("config encryption root..."); |
| 97 | mbox.ble_subsystem | 93 | ble.write_config_data(&ConfigData::encryption_root(&get_erk()).build()) |
| 98 | .write_config_data(&ConfigData::encryption_root(&get_erk()).build()) | ||
| 99 | .await; | 94 | .await; |
| 100 | let response = mbox.ble_subsystem.read().await.unwrap(); | 95 | let response = ble.read().await.unwrap(); |
| 101 | info!("{}", response); | 96 | info!("{}", response); |
| 102 | 97 | ||
| 103 | info!("config tx power level..."); | 98 | info!("config tx power level..."); |
| 104 | mbox.ble_subsystem.set_tx_power_level(PowerLevel::ZerodBm).await; | 99 | ble.set_tx_power_level(PowerLevel::ZerodBm).await; |
| 105 | let response = mbox.ble_subsystem.read().await.unwrap(); | 100 | let response = ble.read().await.unwrap(); |
| 106 | info!("{}", response); | 101 | info!("{}", response); |
| 107 | 102 | ||
| 108 | info!("GATT init..."); | 103 | info!("GATT init..."); |
| 109 | mbox.ble_subsystem.init_gatt().await; | 104 | ble.init_gatt().await; |
| 110 | let response = mbox.ble_subsystem.read().await.unwrap(); | 105 | let response = ble.read().await.unwrap(); |
| 111 | info!("{}", response); | 106 | info!("{}", response); |
| 112 | 107 | ||
| 113 | info!("GAP init..."); | 108 | info!("GAP init..."); |
| 114 | mbox.ble_subsystem | 109 | ble.init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH).await; |
| 115 | .init_gap(Role::PERIPHERAL, false, BLE_GAP_DEVICE_NAME_LENGTH) | 110 | let response = ble.read().await.unwrap(); |
| 116 | .await; | ||
| 117 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 118 | info!("{}", response); | 111 | info!("{}", response); |
| 119 | 112 | ||
| 120 | // info!("set scan response..."); | 113 | // info!("set scan response..."); |
| 121 | // mbox.ble_subsystem.le_set_scan_response_data(&[]).await.unwrap(); | 114 | // ble.le_set_scan_response_data(&[]).await.unwrap(); |
| 122 | // let response = mbox.ble_subsystem.read().await.unwrap(); | 115 | // let response = ble.read().await.unwrap(); |
| 123 | // info!("{}", response); | 116 | // info!("{}", response); |
| 124 | 117 | ||
| 125 | info!("set discoverable..."); | 118 | info!("set discoverable..."); |
| 126 | mbox.ble_subsystem | 119 | ble.set_discoverable(&DiscoverableParameters { |
| 127 | .set_discoverable(&DiscoverableParameters { | 120 | advertising_type: AdvertisingType::NonConnectableUndirected, |
| 128 | advertising_type: AdvertisingType::NonConnectableUndirected, | 121 | advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))), |
| 129 | advertising_interval: Some((Duration::from_millis(250), Duration::from_millis(250))), | 122 | address_type: OwnAddressType::Public, |
| 130 | address_type: OwnAddressType::Public, | 123 | filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan, |
| 131 | filter_policy: AdvertisingFilterPolicy::AllowConnectionAndScan, | 124 | local_name: None, |
| 132 | local_name: None, | 125 | advertising_data: &[], |
| 133 | advertising_data: &[], | 126 | conn_interval: (None, None), |
| 134 | conn_interval: (None, None), | 127 | }) |
| 135 | }) | 128 | .await |
| 136 | .await | 129 | .unwrap(); |
| 137 | .unwrap(); | 130 | |
| 138 | 131 | let response = ble.read().await; | |
| 139 | let response = mbox.ble_subsystem.read().await; | ||
| 140 | info!("{}", response); | 132 | info!("{}", response); |
| 141 | 133 | ||
| 142 | // remove some advertisement to decrease the packet size | 134 | // remove some advertisement to decrease the packet size |
| 143 | info!("delete tx power ad type..."); | 135 | info!("delete tx power ad type..."); |
| 144 | mbox.ble_subsystem | 136 | ble.delete_ad_type(AdvertisingDataType::TxPowerLevel).await; |
| 145 | .delete_ad_type(AdvertisingDataType::TxPowerLevel) | 137 | let response = ble.read().await.unwrap(); |
| 146 | .await; | ||
| 147 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 148 | info!("{}", response); | 138 | info!("{}", response); |
| 149 | 139 | ||
| 150 | info!("delete conn interval ad type..."); | 140 | info!("delete conn interval ad type..."); |
| 151 | mbox.ble_subsystem | 141 | ble.delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval) |
| 152 | .delete_ad_type(AdvertisingDataType::PeripheralConnectionInterval) | ||
| 153 | .await; | 142 | .await; |
| 154 | let response = mbox.ble_subsystem.read().await.unwrap(); | 143 | let response = ble.read().await.unwrap(); |
| 155 | info!("{}", response); | 144 | info!("{}", response); |
| 156 | 145 | ||
| 157 | info!("update advertising data..."); | 146 | info!("update advertising data..."); |
| 158 | mbox.ble_subsystem | 147 | ble.update_advertising_data(&eddystone_advertising_data()) |
| 159 | .update_advertising_data(&eddystone_advertising_data()) | ||
| 160 | .await | 148 | .await |
| 161 | .unwrap(); | 149 | .unwrap(); |
| 162 | let response = mbox.ble_subsystem.read().await.unwrap(); | 150 | let response = ble.read().await.unwrap(); |
| 163 | info!("{}", response); | 151 | info!("{}", response); |
| 164 | 152 | ||
| 165 | info!("update advertising data type..."); | 153 | info!("update advertising data type..."); |
| 166 | mbox.ble_subsystem | 154 | ble.update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe]) |
| 167 | .update_advertising_data(&[3, AdvertisingDataType::UuidCompleteList16 as u8, 0xaa, 0xfe]) | ||
| 168 | .await | 155 | .await |
| 169 | .unwrap(); | 156 | .unwrap(); |
| 170 | let response = mbox.ble_subsystem.read().await.unwrap(); | 157 | let response = ble.read().await.unwrap(); |
| 171 | info!("{}", response); | 158 | info!("{}", response); |
| 172 | 159 | ||
| 173 | info!("update advertising data flags..."); | 160 | info!("update advertising data flags..."); |
| 174 | mbox.ble_subsystem | 161 | ble.update_advertising_data(&[ |
| 175 | .update_advertising_data(&[ | 162 | 2, |
| 176 | 2, | 163 | AdvertisingDataType::Flags as u8, |
| 177 | AdvertisingDataType::Flags as u8, | 164 | (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support |
| 178 | (0x02 | 0x04) as u8, // BLE general discoverable, without BR/EDR support | 165 | ]) |
| 179 | ]) | 166 | .await |
| 180 | .await | 167 | .unwrap(); |
| 181 | .unwrap(); | 168 | let response = ble.read().await.unwrap(); |
| 182 | let response = mbox.ble_subsystem.read().await.unwrap(); | ||
| 183 | info!("{}", response); | 169 | info!("{}", response); |
| 184 | 170 | ||
| 185 | info!("Test OK"); | 171 | info!("Test OK"); |
