Clear error flags before returning

Closes #61

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
This commit is contained in:
Daniel Egger 2019-06-05 20:54:41 +02:00
parent d0c81220b2
commit 143f6b2bf8
2 changed files with 8 additions and 1 deletions

View File

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Clear error flags in serial read() before returning
- Revised feature flags for HSI48 clock support
## [v0.14.0] - 2019-04-25

View File

@ -571,16 +571,22 @@ fn read(usart: *const SerialRegisterBlock) -> nb::Result<u8, Error> {
// NOTE(unsafe) atomic read with no side effects
let isr = unsafe { (*usart).isr.read() };
// NOTE(unsafe) write accessor for atomic writes with no side effects
let icr = unsafe { &(*usart).icr };
let err = if isr.pe().bit_is_set() {
icr.write(|w| w.pecf().set_bit());
nb::Error::Other(Error::Parity)
} else if isr.fe().bit_is_set() {
icr.write(|w| w.fecf().set_bit());
nb::Error::Other(Error::Framing)
} else if isr.nf().bit_is_set() {
icr.write(|w| w.ncf().set_bit());
nb::Error::Other(Error::Noise)
} else if isr.ore().bit_is_set() {
icr.write(|w| w.orecf().set_bit());
nb::Error::Other(Error::Overrun)
} else if isr.rxne().bit_is_set() {
// NOTE(read_volatile) see `write_volatile` below
return Ok(unsafe { ptr::read_volatile(&(*usart).rdr as *const _ as *const _) });
} else {
return Err(nb::Error::WouldBlock);