Hiya!
I am writing code to add support for USB on the NRF58233/58240 to MakeCode. MakeCode relies upon WebUSB. At any point, a user can close the website which causes the web usb stack to stop reading from the device. When this happens, the synchronous code I've written hangs indefinitely.
I have added a software timeout that causes the NRF to exit the while loop and resume application operation until it gets an out transaction from the host. The timeout however is too short on some occasions and times out prematurely.
Instead of increasing the timeout, is there a more elegant way to detect that the host is no longer reading a transaction? Isn't it weird that the EPDATA event is not triggered?
I attach a reference to the code:
codal-nrf52/NRF52USB.cpp at master · lancaster-university/codal-nrf52 (github.com)
and a screenshot from my usb analyser with the timeout in the above code removed:

After line 5471, the MCU has entered the while loop on EVENTS_EPDATA which it never exits. I am at this time using an NRF52833 DK (PCA10100 v0.7.0) and a NRF52840-DK (PCA10056 v2.0.1). The issue is present on both DKs.
Happy to share binaries as required...