tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

MSC Device: Add asynchronous IO support

Open HiFiPhile opened this issue 11 months ago • 2 comments

Describe the PR

Currently, mixing the MSC class with other classes could be problematic since IO operations could block tud_task() for a long time and degrade real-time performance, especially for isochronous and interrupt transfer-based classes.

Now, it's possible to delegate IO operations to a background task.

The cdc_msc_freertos example has been updated for demonstration. One can change CFG_EXAMPLE_MSC_IO_DELAY_MS to a high value and type in the console while doing disk IO. With CFG_EXAMPLE_MSC_ASYNC_IO ON and OFF, the latency difference should be very noticeable.

HiFiPhile avatar Jan 29 '25 16:01 HiFiPhile

I'm using this in a work project. I'd love to see something around these lines landed.

602p avatar Apr 09 '25 07:04 602p

This is a very practical feature, and I also hope that it can be implemented as soon as possible.

DazzlingOkami avatar Apr 09 '25 07:04 DazzlingOkami

Thank you, use cbw.command[0] for pending IO command made it easier to for command extension :)

Without usbd_defer_func proc_read_io_data\proc_write_io_data will be executed in IO task's context, I think it's risky to have both IO task and TUSB task to modify class internal state simultaneously.

HiFiPhile avatar Jul 01 '25 14:07 HiFiPhile

Thank you, use cbw.command[0] for pending IO command made it easier to for command extension :)

Without usbd_defer_func proc_read_io_data\proc_write_io_data will be executed in IO task's context, I think it's risky to have both IO task and TUSB task to modify class internal state simultaneously.

Yeah, I think you are right, I will revert that to force usbd defer

hathach avatar Jul 01 '25 14:07 hathach