diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index f61228750..bd8da8709 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix conflict between `RtcClock::get_xtal_freq` and `Rtc::disable_rom_message_printing` (#2360) - Fixed an issue where interrupts enabled before `esp_hal::init` were disabled. This issue caused the executor created by `#[esp_hal_embassy::main]` to behave incorrectly in multi-core applications. (#2377) +- Fixed `TWAI::transmit_async`: bus-off state is not reached when CANH and CANL are shorted. (#2421) ### Removed diff --git a/esp-hal/src/twai/mod.rs b/esp-hal/src/twai/mod.rs index eaed7d142..7d4c148f7 100644 --- a/esp-hal/src/twai/mod.rs +++ b/esp-hal/src/twai/mod.rs @@ -1943,6 +1943,22 @@ mod asynch { } if intr_status.bits() & 0b11111100 > 0 { + let err_capture = register_block.err_code_cap().read(); + let status = register_block.status().read(); + + // Read error code direction (transmitting or receiving) + cfg_if::cfg_if! { + if #[cfg(any(esp32, esp32c3, esp32s2, esp32s3))] { + let ecc_direction = err_capture.ecc_direction().bit_is_set(); + } else { + let ecc_direction = err_capture.err_capture_code_direction().bit_is_set(); + } + } + // If the error comes from Tx and Tx request is pending + if !ecc_direction && !status.tx_buf_st().bit_is_set() { + // Cancel a pending transmission request + register_block.cmd().write(|w| w.abort_tx().set_bit()); + } async_state.err_waker.wake(); }