embedded-error icon indicating copy to clipboard operation
embedded-error copied to clipboard

UARTs can report multiple errors at once

Open AlyoshaVasilieva opened this issue 5 years ago • 1 comments

This library models a serial error as such:

pub enum SerialError {
    Overrun,
    FrameFormat,
    Parity,
    Noise,
    Impl(ImplError),
}

However, the NXP i.MX RT1062 can report multiple errors per received word.

imxrt-hal handles this using bitflags: https://github.com/imxrt-rs/imxrt-rs/blob/017a970596a59145dce29342fb2a6e45f2fa5722/imxrt-hal/src/uart.rs#L573. I've experienced multiple errors per byte when trying to communicate with a device before it was ready, so it does happen in practice.

I think the STM32F4 series and STM32H7 series can also report multiple errors at once, but I use these less and am not certain.

I am by no means an expert in embedded programming but I think this model is wrong, as hardware works differently.

AlyoshaVasilieva avatar Sep 29 '20 03:09 AlyoshaVasilieva

I've experienced multiple errors per byte when trying to communicate with a device before it was ready, so it does happen in practice.

In that case the HAL would pick the most dominant error or the one that an application might be most likely to handle. This is really no different from e.g. standard errors where also multiple errors could occur at once but only one can be reported.

I am by no means an expert in embedded programming but I think this model is wrong, as hardware works differently.

That's exactly the purpose of this model to abstract over different hardware. Instead of replacing your type with SerialError you can continue to use it as is and add a Into<SerialError> impl for it. That way i.MX applications can still make use of the fancy custom error as-is but you can also use generic applications and drivers with that MCU.

Or did you have any other ideas in mind?

therealprof avatar Sep 29 '20 07:09 therealprof