Serial.onEvent not firing

I am reading how to interact with USB, and having issues.

The docs say you can just attach an event listener like so: Serial.onEvent(ARDUINO_HW_CDC_RX_EVENT, _onUsbEvent0); - the intention is to get called when there is any data to read from Serial.

However, the _onUsbEvent0 function never gets invoked. Is there any special configuration that is needed?


Just to make sure that things are wired correctly, I created a task that wakes up every 10ms and checks that Serial.available() > 0, and in that case reads from it. This works as intended - I can see the data show up, and I can read the data. So it really is about onEvent specifically.


This is LilyGo based on ESP32-S3, in case this matters.


Ok, by popular request, here's the reproducer.

There's not much to see - main.cpp basically initialized comms using some default config (which is just defaults). The meat of the problem is in comms.cpp, the initialization routine.

If I use it as is - i.e. as presented in the commit - I am able to communicate. If I comment out lines 85..86, and uncomment line 83 alone or together with line 84, then I don't see any _onUsbEvent0 calls, and no communication happens.

Communication is performed using scan.c in the same project. It opens a fixed USB device, writes a command, and waits for N responses.

Welcome to the forum

Please post a link to this

An example sketch, posted using code tags, would also be useful

The sketch is large, so I can't post it.

arduino-esp32/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino at master · espressif/arduino-esp32 · GitHub - this is how onEvent is used in ESP32 example. Ok, I see they begin after attaching a callback, and I have it before that, so maybe that's important (although looking at the HWCDC code, I don't see that it would matter)

1 Like

You can always trim it to a minimal reproducible example; by doing so one often finds the problem.

Updated the post

Ok, see updated reference to the post.

hahaha, it turned out to be a typo. I was looking for events of type ARDUINO_USB_CDC_RX_EVENT, as prompted by the IDE, but it should be ARDUINO_HW_CDC_RX_EVENT.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.