Skip to content

Commit e6ae626

Browse files
authored
Merge pull request #99 from Disasm/pac-accesses
Replace volatile access with pac register read/write
2 parents bf77bfc + 154495b commit e6ae626

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/serial.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
use core::{
6262
fmt::{Result, Write},
6363
ops::Deref,
64-
ptr,
6564
};
6665

6766
use embedded_hal::prelude::*;
@@ -558,8 +557,7 @@ fn write(usart: *const SerialRegisterBlock, byte: u8) -> nb::Result<(), void::Vo
558557

559558
if isr.txe().bit_is_set() {
560559
// NOTE(unsafe) atomic write to stateless register
561-
// NOTE(write_volatile) 8-bit write that's not possible through the svd2rust API
562-
unsafe { ptr::write_volatile(&(*usart).tdr as *const _ as *mut _, byte) }
560+
unsafe { (*usart).tdr.write(|w| w.tdr().bits(byte as u16)) }
563561
Ok(())
564562
} else {
565563
Err(nb::Error::WouldBlock)
@@ -587,7 +585,7 @@ fn read(usart: *const SerialRegisterBlock) -> nb::Result<u8, Error> {
587585
icr.write(|w| w.orecf().set_bit());
588586
nb::Error::Other(Error::Overrun)
589587
} else if isr.rxne().bit_is_set() {
590-
return Ok(unsafe { ptr::read_volatile(&(*usart).rdr as *const _ as *const _) });
588+
return Ok(unsafe { (*usart).rdr.read().rdr().bits() as u8 });
591589
} else {
592590
return Err(nb::Error::WouldBlock);
593591
};

0 commit comments

Comments
 (0)