diff options
| author | xoviat <[email protected]> | 2025-12-03 18:15:52 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-12-03 18:15:52 -0600 |
| commit | 7c7f6ce38600b9fbc99a1a0129d00cc2dbcb8406 (patch) | |
| tree | a1097edfd08ea6f92ab00641889c923dc0276da5 | |
| parent | 201502e308564a233bf3649b1a974d5d4374bd96 (diff) | |
wpan: refactor into wb55
| -rw-r--r-- | embassy-stm32-wpan/Cargo.toml | 43 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/lib.rs | 199 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mod.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/channels.rs (renamed from embassy-stm32-wpan/src/channels.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/cmd.rs (renamed from embassy-stm32-wpan/src/cmd.rs) | 2 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/consts.rs (renamed from embassy-stm32-wpan/src/consts.rs) | 2 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/evt.rs (renamed from embassy-stm32-wpan/src/evt.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/fmt.rs (renamed from embassy-stm32-wpan/src/fmt.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/lhci.rs (renamed from embassy-stm32-wpan/src/lhci.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/commands.rs (renamed from embassy-stm32-wpan/src/mac/commands.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/consts.rs (renamed from embassy-stm32-wpan/src/mac/consts.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/control.rs (renamed from embassy-stm32-wpan/src/mac/control.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/driver.rs (renamed from embassy-stm32-wpan/src/mac/driver.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/event.rs (renamed from embassy-stm32-wpan/src/mac/event.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/indications.rs (renamed from embassy-stm32-wpan/src/mac/indications.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/macros.rs (renamed from embassy-stm32-wpan/src/mac/macros.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/mod.rs (renamed from embassy-stm32-wpan/src/mac/mod.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/opcodes.rs (renamed from embassy-stm32-wpan/src/mac/opcodes.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/responses.rs (renamed from embassy-stm32-wpan/src/mac/responses.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/runner.rs (renamed from embassy-stm32-wpan/src/mac/runner.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mac/typedefs.rs (renamed from embassy-stm32-wpan/src/mac/typedefs.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/mod.rs | 198 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/shci.rs (renamed from embassy-stm32-wpan/src/shci.rs) | 2 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/sub/ble.rs (renamed from embassy-stm32-wpan/src/sub/ble.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/sub/mac.rs (renamed from embassy-stm32-wpan/src/sub/mac.rs) | 0 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/sub/mm.rs (renamed from embassy-stm32-wpan/src/sub/mm.rs) | 6 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/sub/mod.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/sub/sys.rs (renamed from embassy-stm32-wpan/src/sub/sys.rs) | 8 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/tables.rs (renamed from embassy-stm32-wpan/src/tables.rs) | 14 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/wb55/unsafe_linked_list.rs (renamed from embassy-stm32-wpan/src/unsafe_linked_list.rs) | 0 | ||||
| -rw-r--r-- | examples/stm32wb/Cargo.toml | 4 | ||||
| -rw-r--r-- | tests/stm32/Cargo.toml | 6 |
32 files changed, 267 insertions, 229 deletions
diff --git a/embassy-stm32-wpan/Cargo.toml b/embassy-stm32-wpan/Cargo.toml index 05d76f4a6..92218ecc1 100644 --- a/embassy-stm32-wpan/Cargo.toml +++ b/embassy-stm32-wpan/Cargo.toml | |||
| @@ -20,10 +20,10 @@ build = [ | |||
| 20 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-stm32-wpan-v$VERSION/embassy-stm32-wpan/src/" | 20 | src_base = "https://github.com/embassy-rs/embassy/blob/embassy-stm32-wpan-v$VERSION/embassy-stm32-wpan/src/" |
| 21 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-stm32-wpan/src/" | 21 | src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-stm32-wpan/src/" |
| 22 | target = "thumbv7em-none-eabihf" | 22 | target = "thumbv7em-none-eabihf" |
| 23 | features = ["stm32wb55rg", "ble", "mac"] | 23 | features = ["stm32wb55rg", "wb55_ble", "wb55_mac"] |
| 24 | 24 | ||
| 25 | [package.metadata.docs.rs] | 25 | [package.metadata.docs.rs] |
| 26 | features = ["stm32wb55rg", "ble", "mac"] | 26 | features = ["stm32wb55rg", "wb55_ble", "wb55_mac"] |
| 27 | 27 | ||
| 28 | [dependencies] | 28 | [dependencies] |
| 29 | embassy-stm32 = { version = "0.4.0", path = "../embassy-stm32" } | 29 | embassy-stm32 = { version = "0.4.0", path = "../embassy-stm32" } |
| @@ -34,6 +34,7 @@ embassy-hal-internal = { version = "0.3.0", path = "../embassy-hal-internal" } | |||
| 34 | embassy-embedded-hal = { version = "0.5.0", path = "../embassy-embedded-hal" } | 34 | embassy-embedded-hal = { version = "0.5.0", path = "../embassy-embedded-hal" } |
| 35 | embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver", optional=true } | 35 | embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver", optional=true } |
| 36 | smoltcp = { version = "0.12.0", optional=true, default-features = false } | 36 | smoltcp = { version = "0.12.0", optional=true, default-features = false } |
| 37 | stm32-bindings = { version = "0.1.1", optional=true, default-features = false } | ||
| 37 | 38 | ||
| 38 | defmt = { version = "1.0.1", optional = true } | 39 | defmt = { version = "1.0.1", optional = true } |
| 39 | log = { version = "0.4.17", optional = true } | 40 | log = { version = "0.4.17", optional = true } |
| @@ -52,8 +53,8 @@ bitflags = { version = "2.3.3", optional = true } | |||
| 52 | [features] | 53 | [features] |
| 53 | defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-internal/defmt", "stm32wb-hci?/defmt"] | 54 | defmt = ["dep:defmt", "embassy-sync/defmt", "embassy-embedded-hal/defmt", "embassy-hal-internal/defmt", "stm32wb-hci?/defmt"] |
| 54 | 55 | ||
| 55 | ble = ["dep:stm32wb-hci"] | 56 | wb55_ble = ["dep:stm32wb-hci"] |
| 56 | mac = ["dep:bitflags", "dep:embassy-net-driver", "dep:smoltcp", "smoltcp/medium-ieee802154"] | 57 | wb55_mac = ["dep:bitflags", "dep:embassy-net-driver", "dep:smoltcp", "smoltcp/medium-ieee802154"] |
| 57 | 58 | ||
| 58 | extended = [] | 59 | extended = [] |
| 59 | 60 | ||
| @@ -73,3 +74,37 @@ stm32wb55vc = [ "embassy-stm32/stm32wb55vc" ] | |||
| 73 | stm32wb55ve = [ "embassy-stm32/stm32wb55ve" ] | 74 | stm32wb55ve = [ "embassy-stm32/stm32wb55ve" ] |
| 74 | stm32wb55vg = [ "embassy-stm32/stm32wb55vg" ] | 75 | stm32wb55vg = [ "embassy-stm32/stm32wb55vg" ] |
| 75 | stm32wb55vy = [ "embassy-stm32/stm32wb55vy" ] | 76 | stm32wb55vy = [ "embassy-stm32/stm32wb55vy" ] |
| 77 | stm32wba50ke = [ "embassy-stm32/stm32wba50ke" ] | ||
| 78 | stm32wba50kg = [ "embassy-stm32/stm32wba50kg" ] | ||
| 79 | stm32wba52ce = [ "embassy-stm32/stm32wba52ce" ] | ||
| 80 | stm32wba52cg = [ "embassy-stm32/stm32wba52cg" ] | ||
| 81 | stm32wba52ke = [ "embassy-stm32/stm32wba52ke" ] | ||
| 82 | stm32wba52kg = [ "embassy-stm32/stm32wba52kg" ] | ||
| 83 | stm32wba54ce = [ "embassy-stm32/stm32wba54ce" ] | ||
| 84 | stm32wba54cg = [ "embassy-stm32/stm32wba54cg" ] | ||
| 85 | stm32wba54ke = [ "embassy-stm32/stm32wba54ke" ] | ||
| 86 | stm32wba54kg = [ "embassy-stm32/stm32wba54kg" ] | ||
| 87 | stm32wba55ce = [ "embassy-stm32/stm32wba55ce" ] | ||
| 88 | stm32wba55cg = [ "embassy-stm32/stm32wba55cg" ] | ||
| 89 | stm32wba55he = [ "embassy-stm32/stm32wba55he" ] | ||
| 90 | stm32wba55hg = [ "embassy-stm32/stm32wba55hg" ] | ||
| 91 | stm32wba55ue = [ "embassy-stm32/stm32wba55ue" ] | ||
| 92 | stm32wba55ug = [ "embassy-stm32/stm32wba55ug" ] | ||
| 93 | stm32wba62cg = [ "embassy-stm32/stm32wba62cg" ] | ||
| 94 | stm32wba62ci = [ "embassy-stm32/stm32wba62ci" ] | ||
| 95 | stm32wba62mg = [ "embassy-stm32/stm32wba62mg" ] | ||
| 96 | stm32wba62mi = [ "embassy-stm32/stm32wba62mi" ] | ||
| 97 | stm32wba62pg = [ "embassy-stm32/stm32wba62pg" ] | ||
| 98 | stm32wba62pi = [ "embassy-stm32/stm32wba62pi" ] | ||
| 99 | stm32wba63cg = [ "embassy-stm32/stm32wba63cg" ] | ||
| 100 | stm32wba63ci = [ "embassy-stm32/stm32wba63ci" ] | ||
| 101 | stm32wba64cg = [ "embassy-stm32/stm32wba64cg" ] | ||
| 102 | stm32wba64ci = [ "embassy-stm32/stm32wba64ci" ] | ||
| 103 | stm32wba65cg = [ "embassy-stm32/stm32wba65cg" ] | ||
| 104 | stm32wba65ci = [ "embassy-stm32/stm32wba65ci" ] | ||
| 105 | stm32wba65mg = [ "embassy-stm32/stm32wba65mg" ] | ||
| 106 | stm32wba65mi = [ "embassy-stm32/stm32wba65mi" ] | ||
| 107 | stm32wba65pg = [ "embassy-stm32/stm32wba65pg" ] | ||
| 108 | stm32wba65pi = [ "embassy-stm32/stm32wba65pi" ] | ||
| 109 | stm32wba65rg = [ "embassy-stm32/stm32wba65rg" ] | ||
| 110 | stm32wba65ri = [ "embassy-stm32/stm32wba65ri" ] | ||
diff --git a/embassy-stm32-wpan/src/lib.rs b/embassy-stm32-wpan/src/lib.rs index 18b0feada..bd58a0ca7 100644 --- a/embassy-stm32-wpan/src/lib.rs +++ b/embassy-stm32-wpan/src/lib.rs | |||
| @@ -18,201 +18,6 @@ | |||
| 18 | // #![warn(missing_docs)] | 18 | // #![warn(missing_docs)] |
| 19 | #![allow(static_mut_refs)] // TODO: Fix | 19 | #![allow(static_mut_refs)] // TODO: Fix |
| 20 | 20 | ||
| 21 | // This must go FIRST so that all the other modules see its macros. | 21 | mod wb55; |
| 22 | mod fmt; | ||
| 23 | 22 | ||
| 24 | use core::mem::MaybeUninit; | 23 | pub use wb55::*; |
| 25 | use core::sync::atomic::{Ordering, compiler_fence}; | ||
| 26 | |||
| 27 | use embassy_hal_internal::Peri; | ||
| 28 | use embassy_stm32::interrupt; | ||
| 29 | use embassy_stm32::ipcc::{Config, Ipcc, IpccRxChannel, ReceiveInterruptHandler, TransmitInterruptHandler}; | ||
| 30 | use embassy_stm32::peripherals::IPCC; | ||
| 31 | use sub::mm::MemoryManager; | ||
| 32 | use sub::sys::Sys; | ||
| 33 | use tables::*; | ||
| 34 | use unsafe_linked_list::LinkedListNode; | ||
| 35 | |||
| 36 | pub mod channels; | ||
| 37 | pub mod cmd; | ||
| 38 | pub mod consts; | ||
| 39 | pub mod evt; | ||
| 40 | pub mod lhci; | ||
| 41 | pub mod shci; | ||
| 42 | pub mod sub; | ||
| 43 | pub mod tables; | ||
| 44 | pub mod unsafe_linked_list; | ||
| 45 | |||
| 46 | #[cfg(feature = "mac")] | ||
| 47 | pub mod mac; | ||
| 48 | |||
| 49 | #[cfg(feature = "ble")] | ||
| 50 | pub use crate::sub::ble::hci; | ||
| 51 | |||
| 52 | type PacketHeader = LinkedListNode; | ||
| 53 | |||
| 54 | /// Transport Layer for the Mailbox interface | ||
| 55 | pub struct TlMbox<'d> { | ||
| 56 | pub sys_subsystem: Sys<'d>, | ||
| 57 | pub mm_subsystem: MemoryManager<'d>, | ||
| 58 | #[cfg(feature = "ble")] | ||
| 59 | pub ble_subsystem: sub::ble::Ble<'d>, | ||
| 60 | #[cfg(feature = "mac")] | ||
| 61 | pub mac_subsystem: sub::mac::Mac<'d>, | ||
| 62 | pub traces: IpccRxChannel<'d>, | ||
| 63 | } | ||
| 64 | |||
| 65 | impl<'d> TlMbox<'d> { | ||
| 66 | /// Initialise the Transport Layer, and creates and returns a wrapper around it. | ||
| 67 | /// | ||
| 68 | /// This method performs the initialisation laid out in AN5289 annex 14.1. However, it differs | ||
| 69 | /// from the implementation documented in Figure 64, to avoid needing to reference any C | ||
| 70 | /// function pointers. | ||
| 71 | /// | ||
| 72 | /// Annex 14.1 lays out the following methods that should be called: | ||
| 73 | /// 1. tl_mbox.c/TL_Init, which initialises the reference table that is shared between CPU1 | ||
| 74 | /// and CPU2. | ||
| 75 | /// 2. shci_tl.c/shci_init(), which initialises the system transport layer, and in turn | ||
| 76 | /// calls tl_mbox.c/TL_SYS_Init, which initialises SYSTEM_EVT_QUEUE channel. | ||
| 77 | /// 3. tl_mbox.c/TL_MM_Init(), which initialises the channel used for sending memory | ||
| 78 | /// manager commands. | ||
| 79 | /// 4. tl_mbox.c/TL_Enable(), which enables the IPCC, and starts CPU2. | ||
| 80 | /// This implementation initialises all of the shared refernce tables and all IPCC channel that | ||
| 81 | /// would be initialised by this process. The developer should therefore treat this method as | ||
| 82 | /// completing all steps in Figure 64. | ||
| 83 | /// | ||
| 84 | /// Once this method has been called, no system commands may be sent until the CPU2 ready | ||
| 85 | /// signal is received, via [sys_subsystem.read]; this completes the procedure laid out in | ||
| 86 | /// Figure 65. | ||
| 87 | /// | ||
| 88 | /// If the `ble` feature is enabled, at this point, the user should call | ||
| 89 | /// [sys_subsystem.shci_c2_ble_init], before any commands are written to the | ||
| 90 | /// [TlMbox.ble_subsystem] ([sub::ble::Ble::new()] completes the process that would otherwise | ||
| 91 | /// be handled by `TL_BLE_Init`; see Figure 66). This completes the procedure laid out in | ||
| 92 | /// Figure 66. | ||
| 93 | // TODO: document what the user should do after calling init to use the mac_802_15_4 subsystem | ||
| 94 | pub async fn init( | ||
| 95 | ipcc: Peri<'d, IPCC>, | ||
| 96 | _irqs: impl interrupt::typelevel::Binding<interrupt::typelevel::IPCC_C1_RX, ReceiveInterruptHandler> | ||
| 97 | + interrupt::typelevel::Binding<interrupt::typelevel::IPCC_C1_TX, TransmitInterruptHandler>, | ||
| 98 | config: Config, | ||
| 99 | ) -> Self { | ||
| 100 | // this is an inlined version of TL_Init from the STM32WB firmware as requested by AN5289. | ||
| 101 | // HW_IPCC_Init is not called, and its purpose is (presumably?) covered by this | ||
| 102 | // implementation | ||
| 103 | unsafe { | ||
| 104 | TL_REF_TABLE.as_mut_ptr().write_volatile(RefTable { | ||
| 105 | device_info_table: TL_DEVICE_INFO_TABLE.as_ptr(), | ||
| 106 | ble_table: TL_BLE_TABLE.as_ptr(), | ||
| 107 | thread_table: TL_THREAD_TABLE.as_ptr(), | ||
| 108 | sys_table: TL_SYS_TABLE.as_ptr(), | ||
| 109 | mem_manager_table: TL_MEM_MANAGER_TABLE.as_ptr(), | ||
| 110 | traces_table: TL_TRACES_TABLE.as_ptr(), | ||
| 111 | mac_802_15_4_table: TL_MAC_802_15_4_TABLE.as_ptr(), | ||
| 112 | zigbee_table: TL_ZIGBEE_TABLE.as_ptr(), | ||
| 113 | lld_tests_table: TL_LLD_TESTS_TABLE.as_ptr(), | ||
| 114 | ble_lld_table: TL_BLE_LLD_TABLE.as_ptr(), | ||
| 115 | }); | ||
| 116 | |||
| 117 | TL_SYS_TABLE | ||
| 118 | .as_mut_ptr() | ||
| 119 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 120 | TL_DEVICE_INFO_TABLE | ||
| 121 | .as_mut_ptr() | ||
| 122 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 123 | TL_BLE_TABLE | ||
| 124 | .as_mut_ptr() | ||
| 125 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 126 | TL_THREAD_TABLE | ||
| 127 | .as_mut_ptr() | ||
| 128 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 129 | TL_MEM_MANAGER_TABLE | ||
| 130 | .as_mut_ptr() | ||
| 131 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 132 | |||
| 133 | TL_TRACES_TABLE | ||
| 134 | .as_mut_ptr() | ||
| 135 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 136 | TL_MAC_802_15_4_TABLE | ||
| 137 | .as_mut_ptr() | ||
| 138 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 139 | TL_ZIGBEE_TABLE | ||
| 140 | .as_mut_ptr() | ||
| 141 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 142 | TL_LLD_TESTS_TABLE | ||
| 143 | .as_mut_ptr() | ||
| 144 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 145 | TL_BLE_LLD_TABLE | ||
| 146 | .as_mut_ptr() | ||
| 147 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 148 | |||
| 149 | EVT_POOL | ||
| 150 | .as_mut_ptr() | ||
| 151 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 152 | SYS_SPARE_EVT_BUF | ||
| 153 | .as_mut_ptr() | ||
| 154 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 155 | CS_BUFFER | ||
| 156 | .as_mut_ptr() | ||
| 157 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 158 | |||
| 159 | #[cfg(feature = "ble")] | ||
| 160 | { | ||
| 161 | BLE_SPARE_EVT_BUF | ||
| 162 | .as_mut_ptr() | ||
| 163 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 164 | |||
| 165 | BLE_CMD_BUFFER | ||
| 166 | .as_mut_ptr() | ||
| 167 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 168 | HCI_ACL_DATA_BUFFER | ||
| 169 | .as_mut_ptr() | ||
| 170 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 171 | } | ||
| 172 | |||
| 173 | #[cfg(feature = "mac")] | ||
| 174 | { | ||
| 175 | MAC_802_15_4_CMD_BUFFER | ||
| 176 | .as_mut_ptr() | ||
| 177 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 178 | MAC_802_15_4_NOTIF_RSP_EVT_BUFFER | ||
| 179 | .as_mut_ptr() | ||
| 180 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | compiler_fence(Ordering::SeqCst); | ||
| 185 | |||
| 186 | // this is equivalent to `HW_IPCC_Enable`, which is called by `TL_Enable` | ||
| 187 | let [ | ||
| 188 | (_hw_ipcc_ble_cmd_channel, _ipcc_ble_event_channel), | ||
| 189 | (ipcc_system_cmd_rsp_channel, ipcc_system_event_channel), | ||
| 190 | (_ipcc_mac_802_15_4_cmd_rsp_channel, _ipcc_mac_802_15_4_notification_ack_channel), | ||
| 191 | (ipcc_mm_release_buffer_channel, _ipcc_traces_channel), | ||
| 192 | (_ipcc_ble_lld_cmd_channel, _ipcc_ble_lld_rsp_channel), | ||
| 193 | (_ipcc_hci_acl_data_channel, _), | ||
| 194 | ] = Ipcc::new(ipcc, _irqs, config).split(); | ||
| 195 | |||
| 196 | let mm = sub::mm::MemoryManager::new(ipcc_mm_release_buffer_channel); | ||
| 197 | let mut sys = sub::sys::Sys::new(ipcc_system_cmd_rsp_channel, ipcc_system_event_channel); | ||
| 198 | |||
| 199 | debug!("sys event: {}", sys.read().await.payload()); | ||
| 200 | |||
| 201 | Self { | ||
| 202 | sys_subsystem: sys, | ||
| 203 | #[cfg(feature = "ble")] | ||
| 204 | ble_subsystem: sub::ble::Ble::new( | ||
| 205 | _hw_ipcc_ble_cmd_channel, | ||
| 206 | _ipcc_ble_event_channel, | ||
| 207 | _ipcc_hci_acl_data_channel, | ||
| 208 | ), | ||
| 209 | #[cfg(feature = "mac")] | ||
| 210 | mac_subsystem: sub::mac::Mac::new( | ||
| 211 | _ipcc_mac_802_15_4_cmd_rsp_channel, | ||
| 212 | _ipcc_mac_802_15_4_notification_ack_channel, | ||
| 213 | ), | ||
| 214 | mm_subsystem: mm, | ||
| 215 | traces: _ipcc_traces_channel, | ||
| 216 | } | ||
| 217 | } | ||
| 218 | } | ||
diff --git a/embassy-stm32-wpan/src/sub/mod.rs b/embassy-stm32-wpan/src/sub/mod.rs deleted file mode 100644 index bee3dbdf1..000000000 --- a/embassy-stm32-wpan/src/sub/mod.rs +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #[cfg(feature = "ble")] | ||
| 2 | pub mod ble; | ||
| 3 | #[cfg(feature = "mac")] | ||
| 4 | pub mod mac; | ||
| 5 | pub mod mm; | ||
| 6 | pub mod sys; | ||
diff --git a/embassy-stm32-wpan/src/channels.rs b/embassy-stm32-wpan/src/wb55/channels.rs index 58f857136..58f857136 100644 --- a/embassy-stm32-wpan/src/channels.rs +++ b/embassy-stm32-wpan/src/wb55/channels.rs | |||
diff --git a/embassy-stm32-wpan/src/cmd.rs b/embassy-stm32-wpan/src/wb55/cmd.rs index 787c22c4b..34f02d6e7 100644 --- a/embassy-stm32-wpan/src/cmd.rs +++ b/embassy-stm32-wpan/src/wb55/cmd.rs | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | use core::ptr; | 1 | use core::ptr; |
| 2 | use core::sync::atomic::{Ordering, compiler_fence}; | 2 | use core::sync::atomic::{Ordering, compiler_fence}; |
| 3 | 3 | ||
| 4 | use crate::PacketHeader; | ||
| 5 | use crate::consts::TlPacketType; | 4 | use crate::consts::TlPacketType; |
| 5 | use crate::wb55::PacketHeader; | ||
| 6 | 6 | ||
| 7 | #[derive(Copy, Clone)] | 7 | #[derive(Copy, Clone)] |
| 8 | #[repr(C, packed)] | 8 | #[repr(C, packed)] |
diff --git a/embassy-stm32-wpan/src/consts.rs b/embassy-stm32-wpan/src/wb55/consts.rs index 7ecb22974..659e74e69 100644 --- a/embassy-stm32-wpan/src/consts.rs +++ b/embassy-stm32-wpan/src/wb55/consts.rs | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::PacketHeader; | ||
| 2 | use crate::evt::CsEvt; | 1 | use crate::evt::CsEvt; |
| 2 | use crate::wb55::PacketHeader; | ||
| 3 | 3 | ||
| 4 | #[derive(Debug)] | 4 | #[derive(Debug)] |
| 5 | #[repr(C)] | 5 | #[repr(C)] |
diff --git a/embassy-stm32-wpan/src/evt.rs b/embassy-stm32-wpan/src/wb55/evt.rs index f32821269..f32821269 100644 --- a/embassy-stm32-wpan/src/evt.rs +++ b/embassy-stm32-wpan/src/wb55/evt.rs | |||
diff --git a/embassy-stm32-wpan/src/fmt.rs b/embassy-stm32-wpan/src/wb55/fmt.rs index 8ca61bc39..8ca61bc39 100644 --- a/embassy-stm32-wpan/src/fmt.rs +++ b/embassy-stm32-wpan/src/wb55/fmt.rs | |||
diff --git a/embassy-stm32-wpan/src/lhci.rs b/embassy-stm32-wpan/src/wb55/lhci.rs index 59c8bfb5d..59c8bfb5d 100644 --- a/embassy-stm32-wpan/src/lhci.rs +++ b/embassy-stm32-wpan/src/wb55/lhci.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/commands.rs b/embassy-stm32-wpan/src/wb55/mac/commands.rs index d96f0094a..d96f0094a 100644 --- a/embassy-stm32-wpan/src/mac/commands.rs +++ b/embassy-stm32-wpan/src/wb55/mac/commands.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/consts.rs b/embassy-stm32-wpan/src/wb55/mac/consts.rs index 56903d980..56903d980 100644 --- a/embassy-stm32-wpan/src/mac/consts.rs +++ b/embassy-stm32-wpan/src/wb55/mac/consts.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/control.rs b/embassy-stm32-wpan/src/wb55/mac/control.rs index 14c6fdd2b..14c6fdd2b 100644 --- a/embassy-stm32-wpan/src/mac/control.rs +++ b/embassy-stm32-wpan/src/wb55/mac/control.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/driver.rs b/embassy-stm32-wpan/src/wb55/mac/driver.rs index 41171ce3d..41171ce3d 100644 --- a/embassy-stm32-wpan/src/mac/driver.rs +++ b/embassy-stm32-wpan/src/wb55/mac/driver.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/event.rs b/embassy-stm32-wpan/src/wb55/mac/event.rs index 39856e185..39856e185 100644 --- a/embassy-stm32-wpan/src/mac/event.rs +++ b/embassy-stm32-wpan/src/wb55/mac/event.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/indications.rs b/embassy-stm32-wpan/src/wb55/mac/indications.rs index 5673514c9..5673514c9 100644 --- a/embassy-stm32-wpan/src/mac/indications.rs +++ b/embassy-stm32-wpan/src/wb55/mac/indications.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/macros.rs b/embassy-stm32-wpan/src/wb55/mac/macros.rs index 1a988a779..1a988a779 100644 --- a/embassy-stm32-wpan/src/mac/macros.rs +++ b/embassy-stm32-wpan/src/wb55/mac/macros.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/mod.rs b/embassy-stm32-wpan/src/wb55/mac/mod.rs index ac50a6b29..ac50a6b29 100644 --- a/embassy-stm32-wpan/src/mac/mod.rs +++ b/embassy-stm32-wpan/src/wb55/mac/mod.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/opcodes.rs b/embassy-stm32-wpan/src/wb55/mac/opcodes.rs index fd7011873..fd7011873 100644 --- a/embassy-stm32-wpan/src/mac/opcodes.rs +++ b/embassy-stm32-wpan/src/wb55/mac/opcodes.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/responses.rs b/embassy-stm32-wpan/src/wb55/mac/responses.rs index 544fdaae8..544fdaae8 100644 --- a/embassy-stm32-wpan/src/mac/responses.rs +++ b/embassy-stm32-wpan/src/wb55/mac/responses.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/runner.rs b/embassy-stm32-wpan/src/wb55/mac/runner.rs index 3b7d895df..3b7d895df 100644 --- a/embassy-stm32-wpan/src/mac/runner.rs +++ b/embassy-stm32-wpan/src/wb55/mac/runner.rs | |||
diff --git a/embassy-stm32-wpan/src/mac/typedefs.rs b/embassy-stm32-wpan/src/wb55/mac/typedefs.rs index 175d4a37d..175d4a37d 100644 --- a/embassy-stm32-wpan/src/mac/typedefs.rs +++ b/embassy-stm32-wpan/src/wb55/mac/typedefs.rs | |||
diff --git a/embassy-stm32-wpan/src/wb55/mod.rs b/embassy-stm32-wpan/src/wb55/mod.rs new file mode 100644 index 000000000..95cfe09f1 --- /dev/null +++ b/embassy-stm32-wpan/src/wb55/mod.rs | |||
| @@ -0,0 +1,198 @@ | |||
| 1 | // This must go FIRST so that all the other modules see its macros. | ||
| 2 | mod fmt; | ||
| 3 | |||
| 4 | use core::mem::MaybeUninit; | ||
| 5 | use core::sync::atomic::{Ordering, compiler_fence}; | ||
| 6 | |||
| 7 | use embassy_hal_internal::Peri; | ||
| 8 | use embassy_stm32::interrupt; | ||
| 9 | use embassy_stm32::ipcc::{Config, Ipcc, IpccRxChannel, ReceiveInterruptHandler, TransmitInterruptHandler}; | ||
| 10 | use embassy_stm32::peripherals::IPCC; | ||
| 11 | use sub::mm::MemoryManager; | ||
| 12 | use sub::sys::Sys; | ||
| 13 | use tables::*; | ||
| 14 | use unsafe_linked_list::LinkedListNode; | ||
| 15 | |||
| 16 | pub mod channels; | ||
| 17 | pub mod cmd; | ||
| 18 | pub mod consts; | ||
| 19 | pub mod evt; | ||
| 20 | pub mod lhci; | ||
| 21 | pub mod shci; | ||
| 22 | pub mod sub; | ||
| 23 | pub mod tables; | ||
| 24 | pub mod unsafe_linked_list; | ||
| 25 | |||
| 26 | #[cfg(feature = "wb55_mac")] | ||
| 27 | pub mod mac; | ||
| 28 | |||
| 29 | #[cfg(feature = "wb55_ble")] | ||
| 30 | pub use crate::sub::ble::hci; | ||
| 31 | |||
| 32 | type PacketHeader = LinkedListNode; | ||
| 33 | |||
| 34 | /// Transport Layer for the Mailbox interface | ||
| 35 | pub struct TlMbox<'d> { | ||
| 36 | pub sys_subsystem: Sys<'d>, | ||
| 37 | pub mm_subsystem: MemoryManager<'d>, | ||
| 38 | #[cfg(feature = "wb55_ble")] | ||
| 39 | pub ble_subsystem: sub::ble::Ble<'d>, | ||
| 40 | #[cfg(feature = "wb55_mac")] | ||
| 41 | pub mac_subsystem: sub::mac::Mac<'d>, | ||
| 42 | pub traces: IpccRxChannel<'d>, | ||
| 43 | } | ||
| 44 | |||
| 45 | impl<'d> TlMbox<'d> { | ||
| 46 | /// Initialise the Transport Layer, and creates and returns a wrapper around it. | ||
| 47 | /// | ||
| 48 | /// This method performs the initialisation laid out in AN5289 annex 14.1. However, it differs | ||
| 49 | /// from the implementation documented in Figure 64, to avoid needing to reference any C | ||
| 50 | /// function pointers. | ||
| 51 | /// | ||
| 52 | /// Annex 14.1 lays out the following methods that should be called: | ||
| 53 | /// 1. tl_mbox.c/TL_Init, which initialises the reference table that is shared between CPU1 | ||
| 54 | /// and CPU2. | ||
| 55 | /// 2. shci_tl.c/shci_init(), which initialises the system transport layer, and in turn | ||
| 56 | /// calls tl_mbox.c/TL_SYS_Init, which initialises SYSTEM_EVT_QUEUE channel. | ||
| 57 | /// 3. tl_mbox.c/TL_MM_Init(), which initialises the channel used for sending memory | ||
| 58 | /// manager commands. | ||
| 59 | /// 4. tl_mbox.c/TL_Enable(), which enables the IPCC, and starts CPU2. | ||
| 60 | /// This implementation initialises all of the shared refernce tables and all IPCC channel that | ||
| 61 | /// would be initialised by this process. The developer should therefore treat this method as | ||
| 62 | /// completing all steps in Figure 64. | ||
| 63 | /// | ||
| 64 | /// Once this method has been called, no system commands may be sent until the CPU2 ready | ||
| 65 | /// signal is received, via [sys_subsystem.read]; this completes the procedure laid out in | ||
| 66 | /// Figure 65. | ||
| 67 | /// | ||
| 68 | /// If the `ble` feature is enabled, at this point, the user should call | ||
| 69 | /// [sys_subsystem.shci_c2_ble_init], before any commands are written to the | ||
| 70 | /// [TlMbox.ble_subsystem] ([sub::ble::Ble::new()] completes the process that would otherwise | ||
| 71 | /// be handled by `TL_BLE_Init`; see Figure 66). This completes the procedure laid out in | ||
| 72 | /// Figure 66. | ||
| 73 | // TODO: document what the user should do after calling init to use the mac_802_15_4 subsystem | ||
| 74 | pub async fn init( | ||
| 75 | ipcc: Peri<'d, IPCC>, | ||
| 76 | _irqs: impl interrupt::typelevel::Binding<interrupt::typelevel::IPCC_C1_RX, ReceiveInterruptHandler> | ||
| 77 | + interrupt::typelevel::Binding<interrupt::typelevel::IPCC_C1_TX, TransmitInterruptHandler>, | ||
| 78 | config: Config, | ||
| 79 | ) -> Self { | ||
| 80 | // this is an inlined version of TL_Init from the STM32WB firmware as requested by AN5289. | ||
| 81 | // HW_IPCC_Init is not called, and its purpose is (presumably?) covered by this | ||
| 82 | // implementation | ||
| 83 | unsafe { | ||
| 84 | TL_REF_TABLE.as_mut_ptr().write_volatile(RefTable { | ||
| 85 | device_info_table: TL_DEVICE_INFO_TABLE.as_ptr(), | ||
| 86 | ble_table: TL_BLE_TABLE.as_ptr(), | ||
| 87 | thread_table: TL_THREAD_TABLE.as_ptr(), | ||
| 88 | sys_table: TL_SYS_TABLE.as_ptr(), | ||
| 89 | mem_manager_table: TL_MEM_MANAGER_TABLE.as_ptr(), | ||
| 90 | traces_table: TL_TRACES_TABLE.as_ptr(), | ||
| 91 | mac_802_15_4_table: TL_MAC_802_15_4_TABLE.as_ptr(), | ||
| 92 | zigbee_table: TL_ZIGBEE_TABLE.as_ptr(), | ||
| 93 | lld_tests_table: TL_LLD_TESTS_TABLE.as_ptr(), | ||
| 94 | ble_lld_table: TL_BLE_LLD_TABLE.as_ptr(), | ||
| 95 | }); | ||
| 96 | |||
| 97 | TL_SYS_TABLE | ||
| 98 | .as_mut_ptr() | ||
| 99 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 100 | TL_DEVICE_INFO_TABLE | ||
| 101 | .as_mut_ptr() | ||
| 102 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 103 | TL_BLE_TABLE | ||
| 104 | .as_mut_ptr() | ||
| 105 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 106 | TL_THREAD_TABLE | ||
| 107 | .as_mut_ptr() | ||
| 108 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 109 | TL_MEM_MANAGER_TABLE | ||
| 110 | .as_mut_ptr() | ||
| 111 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 112 | |||
| 113 | TL_TRACES_TABLE | ||
| 114 | .as_mut_ptr() | ||
| 115 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 116 | TL_MAC_802_15_4_TABLE | ||
| 117 | .as_mut_ptr() | ||
| 118 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 119 | TL_ZIGBEE_TABLE | ||
| 120 | .as_mut_ptr() | ||
| 121 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 122 | TL_LLD_TESTS_TABLE | ||
| 123 | .as_mut_ptr() | ||
| 124 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 125 | TL_BLE_LLD_TABLE | ||
| 126 | .as_mut_ptr() | ||
| 127 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 128 | |||
| 129 | EVT_POOL | ||
| 130 | .as_mut_ptr() | ||
| 131 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 132 | SYS_SPARE_EVT_BUF | ||
| 133 | .as_mut_ptr() | ||
| 134 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 135 | CS_BUFFER | ||
| 136 | .as_mut_ptr() | ||
| 137 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 138 | |||
| 139 | #[cfg(feature = "wb55_ble")] | ||
| 140 | { | ||
| 141 | BLE_SPARE_EVT_BUF | ||
| 142 | .as_mut_ptr() | ||
| 143 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 144 | |||
| 145 | BLE_CMD_BUFFER | ||
| 146 | .as_mut_ptr() | ||
| 147 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 148 | HCI_ACL_DATA_BUFFER | ||
| 149 | .as_mut_ptr() | ||
| 150 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 151 | } | ||
| 152 | |||
| 153 | #[cfg(feature = "wb55_mac")] | ||
| 154 | { | ||
| 155 | MAC_802_15_4_CMD_BUFFER | ||
| 156 | .as_mut_ptr() | ||
| 157 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 158 | MAC_802_15_4_NOTIF_RSP_EVT_BUFFER | ||
| 159 | .as_mut_ptr() | ||
| 160 | .write_volatile(MaybeUninit::zeroed().assume_init()); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | |||
| 164 | compiler_fence(Ordering::SeqCst); | ||
| 165 | |||
| 166 | // this is equivalent to `HW_IPCC_Enable`, which is called by `TL_Enable` | ||
| 167 | let [ | ||
| 168 | (_hw_ipcc_ble_cmd_channel, _ipcc_ble_event_channel), | ||
| 169 | (ipcc_system_cmd_rsp_channel, ipcc_system_event_channel), | ||
| 170 | (_ipcc_mac_802_15_4_cmd_rsp_channel, _ipcc_mac_802_15_4_notification_ack_channel), | ||
| 171 | (ipcc_mm_release_buffer_channel, _ipcc_traces_channel), | ||
| 172 | (_ipcc_ble_lld_cmd_channel, _ipcc_ble_lld_rsp_channel), | ||
| 173 | (_ipcc_hci_acl_data_channel, _), | ||
| 174 | ] = Ipcc::new(ipcc, _irqs, config).split(); | ||
| 175 | |||
| 176 | let mm = sub::mm::MemoryManager::new(ipcc_mm_release_buffer_channel); | ||
| 177 | let mut sys = sub::sys::Sys::new(ipcc_system_cmd_rsp_channel, ipcc_system_event_channel); | ||
| 178 | |||
| 179 | debug!("sys event: {}", sys.read().await.payload()); | ||
| 180 | |||
| 181 | Self { | ||
| 182 | sys_subsystem: sys, | ||
| 183 | #[cfg(feature = "wb55_ble")] | ||
| 184 | ble_subsystem: sub::ble::Ble::new( | ||
| 185 | _hw_ipcc_ble_cmd_channel, | ||
| 186 | _ipcc_ble_event_channel, | ||
| 187 | _ipcc_hci_acl_data_channel, | ||
| 188 | ), | ||
| 189 | #[cfg(feature = "wb55_mac")] | ||
| 190 | mac_subsystem: sub::mac::Mac::new( | ||
| 191 | _ipcc_mac_802_15_4_cmd_rsp_channel, | ||
| 192 | _ipcc_mac_802_15_4_notification_ack_channel, | ||
| 193 | ), | ||
| 194 | mm_subsystem: mm, | ||
| 195 | traces: _ipcc_traces_channel, | ||
| 196 | } | ||
| 197 | } | ||
| 198 | } | ||
diff --git a/embassy-stm32-wpan/src/shci.rs b/embassy-stm32-wpan/src/wb55/shci.rs index 2d94a9cda..3faa79209 100644 --- a/embassy-stm32-wpan/src/shci.rs +++ b/embassy-stm32-wpan/src/wb55/shci.rs | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | use core::sync::atomic::{Ordering, compiler_fence}; | 1 | use core::sync::atomic::{Ordering, compiler_fence}; |
| 2 | use core::{mem, ptr, slice}; | 2 | use core::{mem, ptr, slice}; |
| 3 | 3 | ||
| 4 | use crate::PacketHeader; | ||
| 5 | use crate::cmd::CmdPacket; | 4 | use crate::cmd::CmdPacket; |
| 6 | use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; | 5 | use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; |
| 7 | use crate::evt::{CcEvt, EvtStub}; | 6 | use crate::evt::{CcEvt, EvtStub}; |
| 7 | use crate::wb55::PacketHeader; | ||
| 8 | 8 | ||
| 9 | const SHCI_OGF: u16 = 0x3F; | 9 | const SHCI_OGF: u16 = 0x3F; |
| 10 | 10 | ||
diff --git a/embassy-stm32-wpan/src/sub/ble.rs b/embassy-stm32-wpan/src/wb55/sub/ble.rs index afc4a510a..afc4a510a 100644 --- a/embassy-stm32-wpan/src/sub/ble.rs +++ b/embassy-stm32-wpan/src/wb55/sub/ble.rs | |||
diff --git a/embassy-stm32-wpan/src/sub/mac.rs b/embassy-stm32-wpan/src/wb55/sub/mac.rs index ce2903e61..ce2903e61 100644 --- a/embassy-stm32-wpan/src/sub/mac.rs +++ b/embassy-stm32-wpan/src/wb55/sub/mac.rs | |||
diff --git a/embassy-stm32-wpan/src/sub/mm.rs b/embassy-stm32-wpan/src/wb55/sub/mm.rs index aac252929..cbb5f130b 100644 --- a/embassy-stm32-wpan/src/sub/mm.rs +++ b/embassy-stm32-wpan/src/wb55/sub/mm.rs | |||
| @@ -11,7 +11,7 @@ use embassy_sync::waitqueue::AtomicWaker; | |||
| 11 | use crate::consts::POOL_SIZE; | 11 | use crate::consts::POOL_SIZE; |
| 12 | use crate::evt; | 12 | use crate::evt; |
| 13 | use crate::evt::EvtPacket; | 13 | use crate::evt::EvtPacket; |
| 14 | #[cfg(feature = "ble")] | 14 | #[cfg(feature = "wb55_ble")] |
| 15 | use crate::tables::BLE_SPARE_EVT_BUF; | 15 | use crate::tables::BLE_SPARE_EVT_BUF; |
| 16 | use crate::tables::{EVT_POOL, FREE_BUF_QUEUE, MemManagerTable, SYS_SPARE_EVT_BUF, TL_MEM_MANAGER_TABLE}; | 16 | use crate::tables::{EVT_POOL, FREE_BUF_QUEUE, MemManagerTable, SYS_SPARE_EVT_BUF, TL_MEM_MANAGER_TABLE}; |
| 17 | use crate::unsafe_linked_list::LinkedListNode; | 17 | use crate::unsafe_linked_list::LinkedListNode; |
| @@ -30,9 +30,9 @@ impl<'a> MemoryManager<'a> { | |||
| 30 | LinkedListNode::init_head(LOCAL_FREE_BUF_QUEUE.as_mut_ptr()); | 30 | LinkedListNode::init_head(LOCAL_FREE_BUF_QUEUE.as_mut_ptr()); |
| 31 | 31 | ||
| 32 | TL_MEM_MANAGER_TABLE.as_mut_ptr().write_volatile(MemManagerTable { | 32 | TL_MEM_MANAGER_TABLE.as_mut_ptr().write_volatile(MemManagerTable { |
| 33 | #[cfg(feature = "ble")] | 33 | #[cfg(feature = "wb55_ble")] |
| 34 | spare_ble_buffer: BLE_SPARE_EVT_BUF.as_ptr().cast(), | 34 | spare_ble_buffer: BLE_SPARE_EVT_BUF.as_ptr().cast(), |
| 35 | #[cfg(not(feature = "ble"))] | 35 | #[cfg(not(feature = "wb55_ble"))] |
| 36 | spare_ble_buffer: core::ptr::null(), | 36 | spare_ble_buffer: core::ptr::null(), |
| 37 | spare_sys_buffer: SYS_SPARE_EVT_BUF.as_ptr().cast(), | 37 | spare_sys_buffer: SYS_SPARE_EVT_BUF.as_ptr().cast(), |
| 38 | blepool: EVT_POOL.as_ptr().cast(), | 38 | blepool: EVT_POOL.as_ptr().cast(), |
diff --git a/embassy-stm32-wpan/src/wb55/sub/mod.rs b/embassy-stm32-wpan/src/wb55/sub/mod.rs new file mode 100644 index 000000000..d3ebd822a --- /dev/null +++ b/embassy-stm32-wpan/src/wb55/sub/mod.rs | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | #[cfg(feature = "wb55_ble")] | ||
| 2 | pub mod ble; | ||
| 3 | #[cfg(feature = "wb55_mac")] | ||
| 4 | pub mod mac; | ||
| 5 | pub mod mm; | ||
| 6 | pub mod sys; | ||
diff --git a/embassy-stm32-wpan/src/sub/sys.rs b/embassy-stm32-wpan/src/wb55/sub/sys.rs index 3ee539bb9..4376314c7 100644 --- a/embassy-stm32-wpan/src/sub/sys.rs +++ b/embassy-stm32-wpan/src/wb55/sub/sys.rs | |||
| @@ -3,13 +3,13 @@ use embassy_stm32::ipcc::{IpccRxChannel, IpccTxChannel}; | |||
| 3 | use crate::cmd::CmdPacket; | 3 | use crate::cmd::CmdPacket; |
| 4 | use crate::consts::TlPacketType; | 4 | use crate::consts::TlPacketType; |
| 5 | use crate::evt::EvtBox; | 5 | use crate::evt::EvtBox; |
| 6 | #[cfg(feature = "ble")] | 6 | #[cfg(feature = "wb55_ble")] |
| 7 | use crate::shci::ShciBleInitCmdParam; | 7 | use crate::shci::ShciBleInitCmdParam; |
| 8 | use crate::shci::{SchiCommandStatus, ShciOpcode}; | 8 | use crate::shci::{SchiCommandStatus, ShciOpcode}; |
| 9 | use crate::sub::mm; | 9 | use crate::sub::mm; |
| 10 | use crate::tables::{SysTable, WirelessFwInfoTable}; | 10 | use crate::tables::{SysTable, WirelessFwInfoTable}; |
| 11 | use crate::unsafe_linked_list::LinkedListNode; | 11 | use crate::unsafe_linked_list::LinkedListNode; |
| 12 | use crate::{SYS_CMD_BUF, SYSTEM_EVT_QUEUE, TL_DEVICE_INFO_TABLE, TL_SYS_TABLE}; | 12 | use crate::wb55::{SYS_CMD_BUF, SYSTEM_EVT_QUEUE, TL_DEVICE_INFO_TABLE, TL_SYS_TABLE}; |
| 13 | 13 | ||
| 14 | /// A guard that, once constructed, allows for sys commands to be sent to CPU2. | 14 | /// A guard that, once constructed, allows for sys commands to be sent to CPU2. |
| 15 | pub struct Sys<'a> { | 15 | pub struct Sys<'a> { |
| @@ -66,7 +66,7 @@ impl<'a> Sys<'a> { | |||
| 66 | unsafe { SchiCommandStatus::from_packet(SYS_CMD_BUF.as_ptr()) } | 66 | unsafe { SchiCommandStatus::from_packet(SYS_CMD_BUF.as_ptr()) } |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | #[cfg(feature = "mac")] | 69 | #[cfg(feature = "wb55_mac")] |
| 70 | pub async fn shci_c2_mac_802_15_4_init(&mut self) -> Result<SchiCommandStatus, ()> { | 70 | pub async fn shci_c2_mac_802_15_4_init(&mut self) -> Result<SchiCommandStatus, ()> { |
| 71 | self.write_and_get_response(ShciOpcode::Mac802_15_4Init, &[]).await | 71 | self.write_and_get_response(ShciOpcode::Mac802_15_4Init, &[]).await |
| 72 | } | 72 | } |
| @@ -77,7 +77,7 @@ impl<'a> Sys<'a> { | |||
| 77 | /// AN5289, Figures 65 and 66). It should only be called after CPU2 sends a system event, via | 77 | /// AN5289, Figures 65 and 66). It should only be called after CPU2 sends a system event, via |
| 78 | /// `HW_IPCC_SYS_EvtNot`, aka `IoBusCallBackUserEvt` (as detailed in Figure 65), aka | 78 | /// `HW_IPCC_SYS_EvtNot`, aka `IoBusCallBackUserEvt` (as detailed in Figure 65), aka |
| 79 | /// [crate::sub::ble::hci::host::uart::UartHci::read]. | 79 | /// [crate::sub::ble::hci::host::uart::UartHci::read]. |
| 80 | #[cfg(feature = "ble")] | 80 | #[cfg(feature = "wb55_ble")] |
| 81 | pub async fn shci_c2_ble_init(&mut self, param: ShciBleInitCmdParam) -> Result<SchiCommandStatus, ()> { | 81 | pub async fn shci_c2_ble_init(&mut self, param: ShciBleInitCmdParam) -> Result<SchiCommandStatus, ()> { |
| 82 | self.write_and_get_response(ShciOpcode::BleInit, param.payload()).await | 82 | self.write_and_get_response(ShciOpcode::BleInit, param.payload()).await |
| 83 | } | 83 | } |
diff --git a/embassy-stm32-wpan/src/tables.rs b/embassy-stm32-wpan/src/wb55/tables.rs index 20d2c190f..2e6a9199b 100644 --- a/embassy-stm32-wpan/src/tables.rs +++ b/embassy-stm32-wpan/src/wb55/tables.rs | |||
| @@ -4,7 +4,7 @@ use aligned::{A4, Aligned}; | |||
| 4 | use bit_field::BitField; | 4 | use bit_field::BitField; |
| 5 | 5 | ||
| 6 | use crate::cmd::{AclDataPacket, CmdPacket}; | 6 | use crate::cmd::{AclDataPacket, CmdPacket}; |
| 7 | #[cfg(feature = "mac")] | 7 | #[cfg(feature = "wb55_mac")] |
| 8 | use crate::consts::C_SIZE_CMD_STRING; | 8 | use crate::consts::C_SIZE_CMD_STRING; |
| 9 | use crate::consts::{POOL_SIZE, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; | 9 | use crate::consts::{POOL_SIZE, TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; |
| 10 | use crate::unsafe_linked_list::LinkedListNode; | 10 | use crate::unsafe_linked_list::LinkedListNode; |
| @@ -242,11 +242,11 @@ pub static mut EVT_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(May | |||
| 242 | pub static mut SYSTEM_EVT_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::zeroed()); | 242 | pub static mut SYSTEM_EVT_QUEUE: Aligned<A4, MaybeUninit<LinkedListNode>> = Aligned(MaybeUninit::zeroed()); |
| 243 | 243 | ||
| 244 | // --------------------- app tables --------------------- | 244 | // --------------------- app tables --------------------- |
| 245 | #[cfg(feature = "mac")] | 245 | #[cfg(feature = "wb55_mac")] |
| 246 | #[unsafe(link_section = "MB_MEM2")] | 246 | #[unsafe(link_section = "MB_MEM2")] |
| 247 | pub static mut MAC_802_15_4_CMD_BUFFER: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); | 247 | pub static mut MAC_802_15_4_CMD_BUFFER: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); |
| 248 | 248 | ||
| 249 | #[cfg(feature = "mac")] | 249 | #[cfg(feature = "wb55_mac")] |
| 250 | #[unsafe(link_section = "MB_MEM2")] | 250 | #[unsafe(link_section = "MB_MEM2")] |
| 251 | pub static mut MAC_802_15_4_NOTIF_RSP_EVT_BUFFER: MaybeUninit< | 251 | pub static mut MAC_802_15_4_NOTIF_RSP_EVT_BUFFER: MaybeUninit< |
| 252 | Aligned<A4, [u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>, | 252 | Aligned<A4, [u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>, |
| @@ -262,21 +262,21 @@ pub static mut SYS_CMD_BUF: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeU | |||
| 262 | pub static mut SYS_SPARE_EVT_BUF: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>> = | 262 | pub static mut SYS_SPARE_EVT_BUF: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>> = |
| 263 | Aligned(MaybeUninit::zeroed()); | 263 | Aligned(MaybeUninit::zeroed()); |
| 264 | 264 | ||
| 265 | #[cfg(feature = "mac")] | 265 | #[cfg(feature = "wb55_mac")] |
| 266 | #[unsafe(link_section = "MB_MEM2")] | 266 | #[unsafe(link_section = "MB_MEM2")] |
| 267 | pub static mut MAC_802_15_4_CNFINDNOT: Aligned<A4, MaybeUninit<[u8; C_SIZE_CMD_STRING]>> = | 267 | pub static mut MAC_802_15_4_CNFINDNOT: Aligned<A4, MaybeUninit<[u8; C_SIZE_CMD_STRING]>> = |
| 268 | Aligned(MaybeUninit::zeroed()); | 268 | Aligned(MaybeUninit::zeroed()); |
| 269 | 269 | ||
| 270 | #[cfg(feature = "ble")] | 270 | #[cfg(feature = "wb55_ble")] |
| 271 | #[unsafe(link_section = "MB_MEM1")] | 271 | #[unsafe(link_section = "MB_MEM1")] |
| 272 | pub static mut BLE_CMD_BUFFER: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); | 272 | pub static mut BLE_CMD_BUFFER: Aligned<A4, MaybeUninit<CmdPacket>> = Aligned(MaybeUninit::zeroed()); |
| 273 | 273 | ||
| 274 | #[cfg(feature = "ble")] | 274 | #[cfg(feature = "wb55_ble")] |
| 275 | #[unsafe(link_section = "MB_MEM2")] | 275 | #[unsafe(link_section = "MB_MEM2")] |
| 276 | pub static mut BLE_SPARE_EVT_BUF: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>> = | 276 | pub static mut BLE_SPARE_EVT_BUF: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + TL_EVT_HEADER_SIZE + 255]>> = |
| 277 | Aligned(MaybeUninit::zeroed()); | 277 | Aligned(MaybeUninit::zeroed()); |
| 278 | 278 | ||
| 279 | #[cfg(feature = "ble")] | 279 | #[cfg(feature = "wb55_ble")] |
| 280 | #[unsafe(link_section = "MB_MEM2")] | 280 | #[unsafe(link_section = "MB_MEM2")] |
| 281 | // fuck these "magic" numbers from ST ---v---v | 281 | // fuck these "magic" numbers from ST ---v---v |
| 282 | pub static mut HCI_ACL_DATA_BUFFER: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + 5 + 251]>> = | 282 | pub static mut HCI_ACL_DATA_BUFFER: Aligned<A4, MaybeUninit<[u8; TL_PACKET_HEADER_SIZE + 5 + 251]>> = |
diff --git a/embassy-stm32-wpan/src/unsafe_linked_list.rs b/embassy-stm32-wpan/src/wb55/unsafe_linked_list.rs index d8bc29763..d8bc29763 100644 --- a/embassy-stm32-wpan/src/unsafe_linked_list.rs +++ b/embassy-stm32-wpan/src/wb55/unsafe_linked_list.rs | |||
diff --git a/examples/stm32wb/Cargo.toml b/examples/stm32wb/Cargo.toml index 83119e3a0..83f7cb56b 100644 --- a/examples/stm32wb/Cargo.toml +++ b/examples/stm32wb/Cargo.toml | |||
| @@ -26,8 +26,8 @@ static_cell = "2" | |||
| 26 | 26 | ||
| 27 | [features] | 27 | [features] |
| 28 | default = ["ble", "mac"] | 28 | default = ["ble", "mac"] |
| 29 | mac = ["embassy-stm32-wpan/mac", "dep:embassy-net"] | 29 | mac = ["embassy-stm32-wpan/wb55_mac", "dep:embassy-net"] |
| 30 | ble = ["embassy-stm32-wpan/ble"] | 30 | ble = ["embassy-stm32-wpan/wb55_ble"] |
| 31 | 31 | ||
| 32 | [[bin]] | 32 | [[bin]] |
| 33 | name = "tl_mbox_ble" | 33 | name = "tl_mbox_ble" |
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index 496a9de18..6ee7f8e84 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml | |||
| @@ -51,8 +51,8 @@ stop = ["embassy-stm32/low-power", "embassy-stm32/low-power-debug-with-sleep"] | |||
| 51 | chrono = ["embassy-stm32/chrono", "dep:chrono"] | 51 | chrono = ["embassy-stm32/chrono", "dep:chrono"] |
| 52 | can = [] | 52 | can = [] |
| 53 | fdcan = [] | 53 | fdcan = [] |
| 54 | ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/ble"] | 54 | ble = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/wb55_ble"] |
| 55 | mac = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/mac"] | 55 | mac = ["dep:embassy-stm32-wpan", "embassy-stm32-wpan/wb55_mac"] |
| 56 | embassy-stm32-wpan = [] | 56 | embassy-stm32-wpan = [] |
| 57 | not-gpdma = [] | 57 | not-gpdma = [] |
| 58 | dac = [] | 58 | dac = [] |
| @@ -77,7 +77,7 @@ embassy-executor = { version = "0.9.0", path = "../../embassy-executor", feature | |||
| 77 | embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "tick-hz-131_072", "defmt-timestamp-uptime"] } | 77 | embassy-time = { version = "0.5.0", path = "../../embassy-time", features = ["defmt", "tick-hz-131_072", "defmt-timestamp-uptime"] } |
| 78 | embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "memory-x", "time-driver-any", "_allow-disable-rtc"] } | 78 | embassy-stm32 = { version = "0.4.0", path = "../../embassy-stm32", features = [ "defmt", "unstable-pac", "memory-x", "time-driver-any", "_allow-disable-rtc"] } |
| 79 | embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } | 79 | embassy-futures = { version = "0.1.2", path = "../../embassy-futures" } |
| 80 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "ble"] } | 80 | embassy-stm32-wpan = { version = "0.1.0", path = "../../embassy-stm32-wpan", optional = true, features = ["defmt", "stm32wb55rg", "wb55_ble"] } |
| 81 | embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] } | 81 | embassy-net = { version = "0.7.1", path = "../../embassy-net", features = ["defmt", "tcp", "udp", "dhcpv4", "medium-ethernet"] } |
| 82 | perf-client = { path = "../perf-client" } | 82 | perf-client = { path = "../perf-client" } |
| 83 | 83 | ||
