diff --git a/CHANGELOG.md b/CHANGELOG.md index ad4080a..5c46a7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Remove duplicate error bits clearing in serial `read()` implementation - Optimize SPI implementation - Use `pac` instead of `stm32` for PAC access and soft-deprecate the former - Updated stm32f0 dependency to v0.10 (breaking change) diff --git a/src/serial.rs b/src/serial.rs index f8786fa..6976ee9 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -573,37 +573,21 @@ fn read(usart: *const SerialRegisterBlock) -> nb::Result { // NOTE(unsafe) write accessor for atomic writes with no side effects let icr = unsafe { &(*usart).icr }; - let err = if isr.pe().bit_is_set() { + if isr.pe().bit_is_set() { icr.write(|w| w.pecf().set_bit()); - nb::Error::Other(Error::Parity) + Err(nb::Error::Other(Error::Parity)) } else if isr.fe().bit_is_set() { icr.write(|w| w.fecf().set_bit()); - nb::Error::Other(Error::Framing) + Err(nb::Error::Other(Error::Framing)) } else if isr.nf().bit_is_set() { icr.write(|w| w.ncf().set_bit()); - nb::Error::Other(Error::Noise) + Err(nb::Error::Other(Error::Noise)) } else if isr.ore().bit_is_set() { icr.write(|w| w.orecf().set_bit()); - nb::Error::Other(Error::Overrun) + Err(nb::Error::Other(Error::Overrun)) } else if isr.rxne().bit_is_set() { - return Ok(unsafe { (*usart).rdr.read().rdr().bits() as u8 }); + Ok(unsafe { (*usart).rdr.read().rdr().bits() as u8 }) } else { - return Err(nb::Error::WouldBlock); - }; - - // NOTE(unsafe) atomic write with no side effects other than clearing the errors we've just handled - unsafe { - (*usart).icr.write(|w| { - w.pecf() - .set_bit() - .fecf() - .set_bit() - .ncf() - .set_bit() - .orecf() - .set_bit() - }) - }; - - Err(err) + Err(nb::Error::WouldBlock) + } }