Skip to content

Fix: TWAI transmit hangs on empty bus - #6070

Merged
bjoernQ merged 3 commits into
esp-rs:mainfrom
bjoernQ:fix-twai-transmit-on-empty-bus
Aug 10, 2026
Merged

Fix: TWAI transmit hangs on empty bus#6070
bjoernQ merged 3 commits into
esp-rs:mainfrom
bjoernQ:fix-twai-transmit-on-empty-bus

Conversation

@bjoernQ

@bjoernQ bjoernQ commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Fixes #5307

We already had an (ignored) HIL test for this issue prepared.

This also restores the async TWAI example we had before - while having non-async and async examples seems redundant, in cases like this it's useful. (i.e. the non-async example didn't show the problem)

Happy to remove one of them if requested. (ideally the non-async)

Changelog

esp-hal

  • Fixed: TWAI transmit async hanging on an "empty" bus

esp-storage

  • No changelog necessary.

esp-radio

  • No changelog necessary.

esp-rom-sys

  • No changelog necessary.

esp-phy

  • No changelog necessary.

@bjoernQ bjoernQ changed the title Fix twai transmit on empty bus Fix: TWAI transmit hangs on empty bus Aug 7, 2026
Comment thread esp-hal/src/twai/mod.rs Outdated
Comment on lines +1527 to +1531
#[cfg(any(esp32, esp32c3, esp32s2, esp32s3))]
let w = w.err_warn_int_ena().bit(enable);
#[cfg(any(esp32c6, esp32h2))]
let w = w.ext_err_warning_int_ena().bit(enable);
w

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes - we should align things

Comment thread esp-hal/src/twai/mod.rs Outdated
// status is still set. Gating on both ensures the bus-off state is
// signalled only once per entry, instead of on every error warning
// interrupt while the state persists.
if int_raw.bits() & 0b100 > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a specific .bit_name().bit_is_set() IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - then I probably should align SVD/PACs first instead of unleash even more cfg hell here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@bjoernQ

bjoernQ commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

/hil full --test misc_drivers

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Triggered full HIL run for #6070.

Run: https://github.com/esp-rs/esp-hal/actions/runs/31190456962

Status update: ✅ HIL (full) run succeeded.

@bjoernQ
bjoernQ force-pushed the fix-twai-transmit-on-empty-bus branch from f2728ea to f2ff42f Compare August 10, 2026 09:38
Comment thread esp-hal/src/twai/mod.rs
Comment on lines +1927 to +1929
if int_raw.err_warn_int_st().bit_is_set()
|| int_raw.err_passive_int_st().bit_is_set()
|| int_raw.bus_err_int_st().bit_is_set()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bit are we not checking here that we did previously? The mask had 4 1s

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yes - we not checking (reserved) anymore 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, that is TWAI_TS_COUNTER_OVFL_INT_ST on the P4

Comment thread esp-hal/src/twai/mod.rs
Comment on lines +1927 to +1929
if int_raw.err_warn_int_st().bit_is_set()
|| int_raw.err_passive_int_st().bit_is_set()
|| int_raw.bus_err_int_st().bit_is_set()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, that is TWAI_TS_COUNTER_OVFL_INT_ST on the P4

@bjoernQ

bjoernQ commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

/hil full --test misc_drivers

@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

Triggered full HIL run for #6070.

Run: https://github.com/esp-rs/esp-hal/actions/runs/31378460140

Status update: HIL (full) run is still in progress or status unknown.

@bjoernQ
bjoernQ added this pull request to the merge queue Aug 10, 2026
Merged via the queue into esp-rs:main with commit 3632cad Aug 10, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TWAI hangs when transmitting on an empty bus

2 participants