Skip to content

Commit

Permalink
fix undefined behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcypress committed Nov 22, 2023
1 parent fd2f2a4 commit 3e93493
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use crate::rcc::{Enable, Rcc, Reset};
use crate::stm32::CRC;
use core::hash::Hasher;
use core::ptr;

/// Extension trait to constrain the CRC peripheral.
pub trait CrcExt {
Expand Down Expand Up @@ -170,11 +169,8 @@ impl Crc {
pub fn feed(&mut self, data: &[u8]) {
let crc = unsafe { &(*CRC::ptr()) };
for byte in data {
unsafe {
// Workaround with svd2rust, it does not generate the byte interface to the DR
// register
ptr::write_volatile(&crc.dr as *const _ as *mut u8, *byte);
}
let ptr = &crc.dr as *const _;
unsafe { core::ptr::write_volatile(ptr as *mut u8, *byte) };
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ macro_rules! spi {
} else if sr.crcerr().bit_is_set() {
nb::Error::Other(Error::Crc)
} else if sr.txe().bit_is_set() {
// NOTE(write_volatile) see note above
unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
let ptr = &self.spi.dr as *const _;
unsafe { core::ptr::write_volatile(ptr as *mut u8, byte) };
return Ok(());
} else {
nb::Error::WouldBlock
Expand Down

0 comments on commit 3e93493

Please sign in to comment.