esp-rs / esp-hal

no_std Hardware Abstraction Layers for ESP32 microcontrollers
https://docs.esp-rs.org/esp-hal/
Apache License 2.0
720 stars 195 forks source link

TWAI receive blocks forever (unless peripheral is initialized by ESP-IDF) #2281

Open Jascha-N opened 3 days ago

Jascha-N commented 3 days ago

Bug description

The TWAI peripheral seems to not be initialized properly on ESP32-S3 (and possibly others). Transmitting seems to work but receiving frames does not (it blocks forever). However when I first flash the device with a ESP-IDF C binary that initializes the TWAI peripheral and then flash it again with the esp-hal Rust binary then receiving magically starts to work. Power cycling the device breaks it again (software resets do not). This happens for both blocking and async TWAI drivers on version 0.20.1 and the main branch.

To Reproduce

On an ESP32-S3 (maybe also on other devices) connected over CAN to another device that periodically sends frames:

  1. Initialize TWAI
  2. Try to receive a frame
  3. Twai::receive/Twai::receive_async never returns

Expected behavior

I expect the frames to be received.

Environment

bugadani commented 1 day ago

Sorry I wasn't able to reproduce your issue, S3 is receiving frames just fine for me. On the other hand I found a few unrelated issues on other chips (fixed in https://github.com/esp-rs/esp-hal/pull/2288). Can you please provide more information about your setup?