diff options
| author | xoviat <[email protected]> | 2025-11-23 18:22:05 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-23 18:22:05 +0000 |
| commit | 1573bd6329af67860757f629b22d2c232504b73f (patch) | |
| tree | 589cd69613bca67a5e06791fa160eefb1531abce | |
| parent | 54a153a9a24a58a7cfa1210f78f61beb913baf2d (diff) | |
| parent | 25cd9603ed738e3e4b90b2644a4323d57de71216 (diff) | |
Merge pull request #4933 from xoviat/wpan3
wpan: use ptr arithmetic and update pac
| -rw-r--r-- | .vscode/settings.json | 7 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/cmd.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/evt.rs | 1 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/shci.rs | 18 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/sys.rs | 17 | ||||
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/ipcc.rs | 2 |
7 files changed, 42 insertions, 28 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index 3c9cce18b..73dfa53a4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json | |||
| @@ -5,6 +5,9 @@ | |||
| 5 | "[markdown]": { | 5 | "[markdown]": { |
| 6 | "editor.formatOnSave": false | 6 | "editor.formatOnSave": false |
| 7 | }, | 7 | }, |
| 8 | "rust-analyzer.rustfmt.extraArgs": [ | ||
| 9 | "+nightly" | ||
| 10 | ], | ||
| 8 | "rust-analyzer.check.allTargets": false, | 11 | "rust-analyzer.check.allTargets": false, |
| 9 | "rust-analyzer.check.noDefaultFeatures": true, | 12 | "rust-analyzer.check.noDefaultFeatures": true, |
| 10 | "rust-analyzer.cargo.noDefaultFeatures": true, | 13 | "rust-analyzer.cargo.noDefaultFeatures": true, |
| @@ -61,8 +64,4 @@ | |||
| 61 | // "examples/stm32wl/Cargo.toml", | 64 | // "examples/stm32wl/Cargo.toml", |
| 62 | // "examples/wasm/Cargo.toml", | 65 | // "examples/wasm/Cargo.toml", |
| 63 | ], | 66 | ], |
| 64 | "rust-analyzer.rustfmt.extraArgs": [ | ||
| 65 | //Uncomment to run rustfmt with nightly-only settings that match the CI | ||
| 66 | // "+nightly" | ||
| 67 | ], | ||
| 68 | } \ No newline at end of file | 67 | } \ No newline at end of file |
diff --git a/embassy-stm32-wpan/src/cmd.rs b/embassy-stm32-wpan/src/cmd.rs index 5c81a4aa7..787c22c4b 100644 --- a/embassy-stm32-wpan/src/cmd.rs +++ b/embassy-stm32-wpan/src/cmd.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use core::ptr; | 1 | use core::ptr; |
| 2 | use core::sync::atomic::{Ordering, compiler_fence}; | ||
| 2 | 3 | ||
| 3 | use crate::PacketHeader; | 4 | use crate::PacketHeader; |
| 4 | use crate::consts::TlPacketType; | 5 | use crate::consts::TlPacketType; |
| @@ -45,11 +46,11 @@ pub struct CmdPacket { | |||
| 45 | 46 | ||
| 46 | impl CmdPacket { | 47 | impl CmdPacket { |
| 47 | pub unsafe fn write_into(cmd_buf: *mut CmdPacket, packet_type: TlPacketType, cmd_code: u16, payload: &[u8]) { | 48 | pub unsafe fn write_into(cmd_buf: *mut CmdPacket, packet_type: TlPacketType, cmd_code: u16, payload: &[u8]) { |
| 48 | let p_cmd_serial = &mut (*cmd_buf).cmdserial as *mut _ as *mut CmdSerialStub; | 49 | let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>()); |
| 49 | let p_payload = &mut (*cmd_buf).cmdserial.cmd.payload as *mut _; | 50 | let p_payload = p_cmd_serial.add(size_of::<CmdSerialStub>()); |
| 50 | 51 | ||
| 51 | ptr::write_volatile( | 52 | ptr::write_unaligned( |
| 52 | p_cmd_serial, | 53 | p_cmd_serial as *mut _, |
| 53 | CmdSerialStub { | 54 | CmdSerialStub { |
| 54 | ty: packet_type as u8, | 55 | ty: packet_type as u8, |
| 55 | cmd_code, | 56 | cmd_code, |
| @@ -58,6 +59,8 @@ impl CmdPacket { | |||
| 58 | ); | 59 | ); |
| 59 | 60 | ||
| 60 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); | 61 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); |
| 62 | |||
| 63 | compiler_fence(Ordering::Release); | ||
| 61 | } | 64 | } |
| 62 | } | 65 | } |
| 63 | 66 | ||
| @@ -87,11 +90,11 @@ pub struct AclDataPacket { | |||
| 87 | 90 | ||
| 88 | impl AclDataPacket { | 91 | impl AclDataPacket { |
| 89 | pub unsafe fn write_into(cmd_buf: *mut AclDataPacket, packet_type: TlPacketType, handle: u16, payload: &[u8]) { | 92 | pub unsafe fn write_into(cmd_buf: *mut AclDataPacket, packet_type: TlPacketType, handle: u16, payload: &[u8]) { |
| 90 | let p_cmd_serial = &mut (*cmd_buf).acl_data_serial as *mut _ as *mut AclDataSerialStub; | 93 | let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>()); |
| 91 | let p_payload = &mut (*cmd_buf).acl_data_serial.acl_data as *mut _; | 94 | let p_payload = p_cmd_serial.add(size_of::<AclDataSerialStub>()); |
| 92 | 95 | ||
| 93 | ptr::write_volatile( | 96 | ptr::write_unaligned( |
| 94 | p_cmd_serial, | 97 | p_cmd_serial as *mut _, |
| 95 | AclDataSerialStub { | 98 | AclDataSerialStub { |
| 96 | ty: packet_type as u8, | 99 | ty: packet_type as u8, |
| 97 | handle: handle, | 100 | handle: handle, |
| @@ -100,5 +103,7 @@ impl AclDataPacket { | |||
| 100 | ); | 103 | ); |
| 101 | 104 | ||
| 102 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); | 105 | ptr::copy_nonoverlapping(payload as *const _ as *const u8, p_payload, payload.len()); |
| 106 | |||
| 107 | compiler_fence(Ordering::Release); | ||
| 103 | } | 108 | } |
| 104 | } | 109 | } |
diff --git a/embassy-stm32-wpan/src/evt.rs b/embassy-stm32-wpan/src/evt.rs index c6528413d..f32821269 100644 --- a/embassy-stm32-wpan/src/evt.rs +++ b/embassy-stm32-wpan/src/evt.rs | |||
| @@ -67,6 +67,7 @@ pub struct EvtSerial { | |||
| 67 | pub struct EvtStub { | 67 | pub struct EvtStub { |
| 68 | pub kind: u8, | 68 | pub kind: u8, |
| 69 | pub evt_code: u8, | 69 | pub evt_code: u8, |
| 70 | pub payload_len: u8, | ||
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | /// This format shall be used for all events (asynchronous and command response) reported | 73 | /// This format shall be used for all events (asynchronous and command response) reported |
diff --git a/embassy-stm32-wpan/src/shci.rs b/embassy-stm32-wpan/src/shci.rs index 30d689716..e93f55598 100644 --- a/embassy-stm32-wpan/src/shci.rs +++ b/embassy-stm32-wpan/src/shci.rs | |||
| @@ -1,6 +1,10 @@ | |||
| 1 | use core::{mem, slice}; | 1 | use core::sync::atomic::{Ordering, compiler_fence}; |
| 2 | use core::{mem, ptr, slice}; | ||
| 2 | 3 | ||
| 4 | use crate::PacketHeader; | ||
| 5 | use crate::cmd::CmdPacket; | ||
| 3 | use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; | 6 | use crate::consts::{TL_CS_EVT_SIZE, TL_EVT_HEADER_SIZE, TL_PACKET_HEADER_SIZE}; |
| 7 | use crate::evt::{CcEvt, EvtStub}; | ||
| 4 | 8 | ||
| 5 | const SHCI_OGF: u16 = 0x3F; | 9 | const SHCI_OGF: u16 = 0x3F; |
| 6 | 10 | ||
| @@ -21,6 +25,18 @@ pub enum SchiCommandStatus { | |||
| 21 | ShciFusCmdNotSupported = 0xFF, | 25 | ShciFusCmdNotSupported = 0xFF, |
| 22 | } | 26 | } |
| 23 | 27 | ||
| 28 | impl SchiCommandStatus { | ||
| 29 | pub unsafe fn from_packet(cmd_buf: *const CmdPacket) -> Result<Self, ()> { | ||
| 30 | let p_cmd_serial = (cmd_buf as *mut u8).add(size_of::<PacketHeader>()); | ||
| 31 | let p_evt_payload = p_cmd_serial.add(size_of::<EvtStub>()); | ||
| 32 | |||
| 33 | compiler_fence(Ordering::Acquire); | ||
| 34 | let cc_evt = ptr::read_unaligned(p_evt_payload as *const CcEvt); | ||
| 35 | |||
| 36 | cc_evt.payload[0].try_into() | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 24 | impl TryFrom<u8> for SchiCommandStatus { | 40 | impl TryFrom<u8> for SchiCommandStatus { |
| 25 | type Error = (); | 41 | type Error = (); |
| 26 | 42 | ||
diff --git a/embassy-stm32-wpan/src/sub/sys.rs b/embassy-stm32-wpan/src/sub/sys.rs index 8a3382f86..549811685 100644 --- a/embassy-stm32-wpan/src/sub/sys.rs +++ b/embassy-stm32-wpan/src/sub/sys.rs | |||
| @@ -1,10 +1,9 @@ | |||
| 1 | use core::ptr; | ||
| 2 | |||
| 3 | use crate::cmd::CmdPacket; | 1 | use crate::cmd::CmdPacket; |
| 4 | use crate::consts::TlPacketType; | 2 | use crate::consts::TlPacketType; |
| 5 | use crate::evt::{CcEvt, EvtBox, EvtPacket}; | 3 | use crate::evt::EvtBox; |
| 6 | #[allow(unused_imports)] | 4 | #[cfg(feature = "ble")] |
| 7 | use crate::shci::{SchiCommandStatus, ShciBleInitCmdParam, ShciOpcode}; | 5 | use crate::shci::ShciBleInitCmdParam; |
| 6 | use crate::shci::{SchiCommandStatus, ShciOpcode}; | ||
| 8 | use crate::sub::mm; | 7 | use crate::sub::mm; |
| 9 | use crate::tables::{SysTable, WirelessFwInfoTable}; | 8 | use crate::tables::{SysTable, WirelessFwInfoTable}; |
| 10 | use crate::unsafe_linked_list::LinkedListNode; | 9 | use crate::unsafe_linked_list::LinkedListNode; |
| @@ -50,13 +49,7 @@ impl Sys { | |||
| 50 | self.write(opcode, payload).await; | 49 | self.write(opcode, payload).await; |
| 51 | Ipcc::flush(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL).await; | 50 | Ipcc::flush(channels::cpu1::IPCC_SYSTEM_CMD_RSP_CHANNEL).await; |
| 52 | 51 | ||
| 53 | unsafe { | 52 | unsafe { SchiCommandStatus::from_packet(SYS_CMD_BUF.as_ptr()) } |
| 54 | let p_event_packet = SYS_CMD_BUF.as_ptr() as *const EvtPacket; | ||
| 55 | let p_command_event = &((*p_event_packet).evt_serial.evt.payload) as *const _ as *const CcEvt; | ||
| 56 | let p_payload = &((*p_command_event).payload) as *const u8; | ||
| 57 | |||
| 58 | ptr::read_volatile(p_payload).try_into() | ||
| 59 | } | ||
| 60 | } | 53 | } |
| 61 | 54 | ||
| 62 | #[cfg(feature = "mac")] | 55 | #[cfg(feature = "mac")] |
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index fbd00895d..e10409112 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -200,11 +200,11 @@ aligned = "0.4.1" | |||
| 200 | heapless = "0.9.1" | 200 | heapless = "0.9.1" |
| 201 | 201 | ||
| 202 | #stm32-metapac = { version = "18" } | 202 | #stm32-metapac = { version = "18" } |
| 203 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-61abfb115273dc66ed99bf14545779a2aa0722c8" } | 203 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f61ed017ef12ec84ff04c49e3147694bda3b29cb" } |
| 204 | 204 | ||
| 205 | [build-dependencies] | 205 | [build-dependencies] |
| 206 | #stm32-metapac = { version = "18", default-features = false, features = ["metadata"]} | 206 | #stm32-metapac = { version = "18", default-features = false, features = ["metadata"]} |
| 207 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-61abfb115273dc66ed99bf14545779a2aa0722c8", default-features = false, features = ["metadata"] } | 207 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-f61ed017ef12ec84ff04c49e3147694bda3b29cb", default-features = false, features = ["metadata"] } |
| 208 | 208 | ||
| 209 | proc-macro2 = "1.0.36" | 209 | proc-macro2 = "1.0.36" |
| 210 | quote = "1.0.15" | 210 | quote = "1.0.15" |
diff --git a/embassy-stm32/src/ipcc.rs b/embassy-stm32/src/ipcc.rs index e1d8b1c2a..b9be1b1d2 100644 --- a/embassy-stm32/src/ipcc.rs +++ b/embassy-stm32/src/ipcc.rs | |||
| @@ -147,7 +147,7 @@ impl Ipcc { | |||
| 147 | // If bit is set to 1 then interrupt is disabled; we want to enable the interrupt | 147 | // If bit is set to 1 then interrupt is disabled; we want to enable the interrupt |
| 148 | regs.cpu(0).mr().modify(|w| w.set_chfm(channel as usize, false)); | 148 | regs.cpu(0).mr().modify(|w| w.set_chfm(channel as usize, false)); |
| 149 | 149 | ||
| 150 | compiler_fence(Ordering::SeqCst); | 150 | compiler_fence(Ordering::Release); |
| 151 | 151 | ||
| 152 | if !regs.cpu(0).sr().read().chf(channel as usize) { | 152 | if !regs.cpu(0).sr().read().chf(channel as usize) { |
| 153 | // If bit is set to 1 then interrupt is disabled; we want to disable the interrupt | 153 | // If bit is set to 1 then interrupt is disabled; we want to disable the interrupt |
