Skip to content

Commit ab6c9b6

Browse files
committed
Replace casts of &T to &mut T with UnsafeCell
Specifically we cast *const T to *const UnsafeCell<T> then use the [UnsafeCell::raw_get](https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html#method.raw_get) method
1 parent 90875db commit ab6c9b6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/spi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::stm32::{RCC, SPI1, SPI2, SPI3};
2020
use crate::time::Hertz;
2121
use core::ptr;
2222
pub use hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
23+
use core::cell::UnsafeCell;
2324

2425
/// SPI error
2526
#[derive(Debug)]
@@ -210,8 +211,9 @@ macro_rules! spi {
210211
} else if sr.crcerr().bit_is_set() {
211212
nb::Error::Other(Error::Crc)
212213
} else if sr.txe().bit_is_set() {
214+
let dr = &self.spi.dr as *const _ as *const UnsafeCell<u8>;
213215
// NOTE(write_volatile) see note above
214-
unsafe { ptr::write_volatile(&self.spi.dr as *const _ as *mut u8, byte) }
216+
unsafe { ptr::write_volatile(UnsafeCell::raw_get(dr), byte) };
215217
return Ok(());
216218
} else {
217219
nb::Error::WouldBlock

0 commit comments

Comments
 (0)