tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

IRQ-safe tud_cdc_n_write variant (lock/stall when flush)

Open MrJake222 opened this issue 1 year ago • 0 comments

Operating System

Linux

Board

RP2040

Firmware

Specifically this version, this fragment: https://github.com/MrJake222/pico-ice-sdk/blob/473e38978f7f8caab7e20c6b49f9f48623158dcf/src/ice_usb.c#L169-L175

What happened ?

When transmitting data over CDC from UART interrupt, the tud_cdc_n_write function can cause a flush, which is highly unwanted in an IRQ. I want to write 64/512 bytes to the buffer, and the rest shouldn't be written (return 0 for example). Flush will be called in main loop (or done automatically by tud_task().

This could be achieved by writing at most BULK_PACKET_SIZE - 1 bytes, but there is no function exposing current fifo level. While possible to calculate the number of bytes currently in the fifo by using tud_cdc_n_write_available, it will be rather cumbersome.

I'm aware that I can just write my own fifo (that's what the library runs right now), but why? There is a perfectly good fifo in TinyUSB code. Or is it really a good idea to use my own fifo?

How to reproduce ?

.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

.

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • [X] I confirm I have checked existing issues, dicussion and documentation.

MrJake222 avatar Nov 01 '24 19:11 MrJake222