Skip to content

ESP TWAI never counts RX bus errors, so a wrong bitrate looks silent #117

Backlog

Description

@Tichael

Problem

On ESP TWAI buses, the RX error count is always 0. So a bus with only errors (wrong bitrate, a CAN FD bus, a wiring fault) looks like a silent bus:

Seen on a WiCAN (ESP32-C3) in an E-GMP car with bus 0 built for 250 kbit/s on the 500 kbit/s M-CAN: every window read 0 frames, 0 RX errors, while the car was sending about 2,160 frames/s (#115 in-car test C).

Cause (esp-hal 1.1.2)

  • TwaiRx::receive_async only returns a frame, EspTwaiError::BusOff or Overrun. The Bit/Stuff/Crc/Form/Acknowledge kinds exist but are never returned.
  • handle_interrupt reads err_code_cap on a bus-error interrupt and discards it: "We might want to use the error code to gather statistics in the future."
  • receive_error_count() doesn't help in listen-only mode: esp-hal sets REC to 128 before leaving reset mode (errata workaround for ESP32/S2/S3/C3), and the counters stay frozen in listen-only mode.

Options

  • Upstream: have esp-hal count or expose bus errors (a counter in the async state, or an error-code callback), then count them in boards/esp/src/can.rs.
  • Local: patch esp-hal ([patch.crates-io]) the same way until upstream has it.
  • Check whether the bus-error interrupt still fires in listen-only mode on the C3 with REC frozen; if it doesn't, this can only work in normal mode.

Done when

A WiCAN at a wrong bitrate on a live bus reports RX errors with no frames: the serial line shows them, and the app shows "No valid frames".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions