Skip to content

Commit 7b7d54d

Browse files
author
Jonathan Pallant (42 Technology)
committed
Pull out the unsafe code.
1 parent 70449c5 commit 7b7d54d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/serial.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,24 @@ macro_rules! hal {
319319
// NOTE(unsafe) atomic read with no side effects
320320
let isr = unsafe { (*$USARTX::ptr()).isr.read() };
321321

322+
// NOTE(unsafe) write accessor for atomic writes with no side effects
323+
let icr = unsafe { &(*$USARTX::ptr()).icr };
324+
322325
Err(if isr.pe().bit_is_set() {
323326
// Clear the bit by writing 1 to the clear register
324-
unsafe { (*$USARTX::ptr()).icr.write(|w| { w.pecf().set_bit() }) };
327+
icr.write(|w| { w.pecf().set_bit() });
325328
nb::Error::Other(Error::Parity)
326329
} else if isr.fe().bit_is_set() {
327330
// Clear the bit by writing 1 to the clear register
328-
unsafe { (*$USARTX::ptr()).icr.write(|w| { w.fecf().set_bit() }) };
331+
icr.write(|w| { w.fecf().set_bit() });
329332
nb::Error::Other(Error::Framing)
330333
} else if isr.nf().bit_is_set() {
331334
// Clear the bit by writing 1 to the clear register
332-
unsafe { (*$USARTX::ptr()).icr.write(|w| { w.ncf().set_bit() }) };
335+
icr.write(|w| { w.ncf().set_bit() });
333336
nb::Error::Other(Error::Noise)
334337
} else if isr.ore().bit_is_set() {
335338
// Clear the bit by writing 1 to the clear register
336-
unsafe { (*$USARTX::ptr()).icr.write(|w| { w.orecf().set_bit() }) };
339+
icr.write(|w| { w.orecf().set_bit() });
337340
nb::Error::Other(Error::Overrun)
338341
} else if isr.rxne().bit_is_set() {
339342
// NOTE(read_volatile) see `write_volatile` below

0 commit comments

Comments
 (0)