ensure DR is read to clear idle/overflow interrupt when they occur independently of the rxne

This commit is contained in:
Peter Gibson 2023-06-14 11:56:44 +10:00
parent 64e3310e64
commit 837950cd74

View File

@ -21,9 +21,15 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
// RX // RX
unsafe { unsafe {
let sr = sr(r).read(); let sr = sr(r).read();
// Reading DR clears the rxne, error and idle interrupt flags on v1.
let dr = if sr.ore() || sr.idle() || sr.rxne() {
Some(rdr(r).read_volatile())
}
else {
None
};
clear_interrupt_flags(r, sr); clear_interrupt_flags(r, sr);
if sr.rxne() {
if sr.pe() { if sr.pe() {
warn!("Parity error"); warn!("Parity error");
} }
@ -36,12 +42,11 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
if sr.ore() { if sr.ore() {
warn!("Overrun error"); warn!("Overrun error");
} }
if sr.rxne() {
let mut rx_writer = state.rx_buf.writer(); let mut rx_writer = state.rx_buf.writer();
let buf = rx_writer.push_slice(); let buf = rx_writer.push_slice();
if !buf.is_empty() { if !buf.is_empty() {
// This read also clears the error and idle interrupt flags on v1. buf[0] = dr.unwrap();
buf[0] = rdr(r).read_volatile();
rx_writer.push_done(1); rx_writer.push_done(1);
} else { } else {
// FIXME: Should we disable any further RX interrupts when the buffer becomes full. // FIXME: Should we disable any further RX interrupts when the buffer becomes full.
@ -54,7 +59,7 @@ impl<T: BasicInstance> interrupt::typelevel::Handler<T::Interrupt> for Interrupt
if sr.idle() { if sr.idle() {
state.rx_waker.wake(); state.rx_waker.wake();
}; }
} }
// TX // TX