Skip to content

Commit

Permalink
Replace bytemuck with custom data conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Krygier committed Jul 19, 2024
1 parent 1fc80e6 commit c5b4cb1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
2 changes: 0 additions & 2 deletions embassy-stm32/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ document-features = "0.2.7"
static_assertions = { version = "1.1" }
volatile-register = { version = "0.2.1" }
bitflags = "2.4.2"
bytemuck = "1.7.3"


[dev-dependencies]
critical-section = { version = "1.1", features = ["std"] }
Expand Down
26 changes: 10 additions & 16 deletions embassy-stm32/src/pka/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,23 +676,17 @@ impl<'d, T: Instance> Pka<'d, T> {

/// Write to PKA RAM with offset
fn write_to_ram(&mut self, offset: usize, data: &[u8]) {
match try_cast_slice(data) {
Ok(u32_data) => {
for (i, byte) in u32_data.iter().enumerate() {
T::regs().ram(offset + i).write_value(*byte);
}

// Write 0 to next word
T::regs().ram(offset + u32_data.len()).write_value(0);
}
Err(_) => {
panic!(
"Data is not aligned to u32. Data size: {}, data: {:x}",
data.len(),
data
);
}
let len = data.len() / 4;
let u32_data = data
.chunks_exact(4)
.map(|b| u32::from_le_bytes([b[0], b[1], b[2], b[3]]));

for (i, byte) in u32_data.enumerate() {
T::regs().ram(offset + i).write_value(byte);
}

// Write 0 to next word
T::regs().ram(offset + len).write_value(0);
}

/// Write to PKA RAM with offset. Don't set the last word to 0
Expand Down

0 comments on commit c5b4cb1

Please sign in to comment.