@@ -319,21 +319,24 @@ macro_rules! hal {
319
319
// NOTE(unsafe) atomic read with no side effects
320
320
let isr = unsafe { ( * $USARTX:: ptr( ) ) . isr. read( ) } ;
321
321
322
+ // NOTE(unsafe) write accessor for atomic writes with no side effects
323
+ let icr = unsafe { & ( * $USARTX:: ptr( ) ) . icr } ;
324
+
322
325
Err ( if isr. pe( ) . bit_is_set( ) {
323
326
// 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( ) } ) ;
325
328
nb:: Error :: Other ( Error :: Parity )
326
329
} else if isr. fe( ) . bit_is_set( ) {
327
330
// 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( ) } ) ;
329
332
nb:: Error :: Other ( Error :: Framing )
330
333
} else if isr. nf( ) . bit_is_set( ) {
331
334
// 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( ) } ) ;
333
336
nb:: Error :: Other ( Error :: Noise )
334
337
} else if isr. ore( ) . bit_is_set( ) {
335
338
// 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( ) } ) ;
337
340
nb:: Error :: Other ( Error :: Overrun )
338
341
} else if isr. rxne( ) . bit_is_set( ) {
339
342
// NOTE(read_volatile) see `write_volatile` below
0 commit comments