Browse Source

Clear UART errors after we've detected and reported them

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
trying.tmp
Daniel Egger 3 years ago
parent
commit
cf4de96aee
  1. 4
      CHANGELOG.md
  2. 22
      src/serial.rs

4
CHANGELOG.md

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Fixed
- Clear UART errors in hardware after handling them
## [v0.15.0] - 2019-08-09
### Changed

22
src/serial.rs

@ -571,7 +571,7 @@ fn read(usart: *const SerialRegisterBlock) -> nb::Result<u8, Error> {
// NOTE(unsafe) atomic read with no side effects
let isr = unsafe { (*usart).isr.read() };
Err(if isr.pe().bit_is_set() {
let err = if isr.pe().bit_is_set() {
nb::Error::Other(Error::Parity)
} else if isr.fe().bit_is_set() {
nb::Error::Other(Error::Framing)
@ -583,6 +583,22 @@ fn read(usart: *const SerialRegisterBlock) -> nb::Result<u8, Error> {
// NOTE(read_volatile) see `write_volatile` below
return Ok(unsafe { ptr::read_volatile(&(*usart).rdr as *const _ as *const _) });
} else {
nb::Error::WouldBlock
})
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()
})
};
return Err(err);
}

Loading…
Cancel
Save