stm32/uart remove DmaUnsynced from public api

Its an internal error which should never be exposed. It should only
occur with wrong driver implementations. We log to the user and return
an Overrun error since handling DmaUnsynced as an Overrun will resolve it.
This commit is contained in:
dvdsk 2024-10-26 12:38:10 +02:00
parent be50b62677
commit edac7cc630
No known key found for this signature in database
GPG Key ID: F687E89FC7894F98
3 changed files with 12 additions and 3 deletions

View File

@ -21,6 +21,10 @@ pub trait DmaCtrl {
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error { pub enum Error {
Overrun, Overrun,
/// the newly read DMA positions don't make sense compared to the previous
/// ones. This can usually only occur due to wrong Driver implementation, if
/// the driver author (or the user using raw metapac code) directly resets
/// the channel for instance.
DmaUnsynced, DmaUnsynced,
} }

View File

@ -260,8 +260,6 @@ pub enum Error {
Parity, Parity,
/// Buffer too large for DMA /// Buffer too large for DMA
BufferTooLong, BufferTooLong,
// TODO: ask what this is and document it (dvdsk)
DmaUnsynced,
} }
enum ReadCompletionEvent { enum ReadCompletionEvent {

View File

@ -268,7 +268,14 @@ impl ReadReady for RingBufferedUartRx<'_> {
fn read_ready(&mut self) -> Result<bool, Self::Error> { fn read_ready(&mut self) -> Result<bool, Self::Error> {
let len = self.ring_buf.len().map_err(|e| match e { let len = self.ring_buf.len().map_err(|e| match e {
crate::dma::ringbuffer::Error::Overrun => Self::Error::Overrun, crate::dma::ringbuffer::Error::Overrun => Self::Error::Overrun,
crate::dma::ringbuffer::Error::DmaUnsynced => Self::Error::DmaUnsynced, crate::dma::ringbuffer::Error::DmaUnsynced => {
error!(
"Ringbuffer error: DmaUNsynced, driver implementation is
probably bugged please open an issue"
);
// we report this as overrun since its recoverable in the same way
Self::Error::Overrun
}
})?; })?;
Ok(len > 0) Ok(len > 0)
} }