Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to make CDC TX buffer persistent. #2629

Merged
merged 1 commit into from
May 8, 2024

Conversation

andrewleech
Copy link
Contributor

@andrewleech andrewleech commented May 8, 2024

Describe the PR
This MR provides a build configuration define that allows an application to prevent clearing of the CDC TX fifo buffer on port setup / reset.

#define CFG_TUD_CDC_PERSISTENT_TX_BUFF (1)

The default if it's not set or set to 0 is the same as current production code.

This means that an application can write data to the CDC port before the USB is connected and available, eg logging data right from application startup. This buffered data will then be flushed down the CDC port on the next write or tud_cdc_write_flush(); after the CDC is connected.

Additional context
Related information: #2595

I'm hoping to add this to support a feature used in micropython. There, the stm port is using the STM usb stack, not TinyUSB. It has a feature where data "sent" to usb CDC at startup is buffered (in the usb stack), before USB is init / connected. Then when USB is connected, data previously buffered is flushed down the line to the client.

In practice, this buffered content consists of a "startup banner" like:

PS C:\Users\anl> mpremote
Connected to MicroPython at COM21
Use Ctrl-] or Ctrl-x to exit this shell

MicroPython v1.23.0-preview.329.gf0f3c92b2f.dirty on 2024-05-08; PCA10059 with NRF52840
Type "help()" for more information.
>>>

This feature has been there for years and is quite popular, I really want to replicate this feature on TinyUSB to use across all ports, eventually replacing the STM usb stack with TinyUSB for consistency with all other micropython ports.

@HiFiPhile
Copy link
Collaborator

Thanks for your PR, please add define and description in cdc_device.h like how #ifndef CFG_TUD_CDC_EP_BUFSIZE does.

@andrewleech
Copy link
Contributor Author

Thanks, I did think the setting should be detailed somewhere, in hindsight cdc_device.h should have been the obvious location!

@HiFiPhile HiFiPhile merged commit c773c61 into hathach:master May 8, 2024
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants