From c2cac44c5ec9ca4eb463312a0b8c249fd9c47ac2 Mon Sep 17 00:00:00 2001 From: Serge Bazanski <q3k@q3k.org> Date: Thu, 17 Aug 2023 14:57:11 +0200 Subject: [PATCH] st3m: partial usb unfucking I have returned from the USB mines bearing great news. The badge should now get less stuck when doing CDC comms. Apparently, TinyUSB does not attempt to flush its CDC TX FIFO unless you request it or unless it just finished another transfer. --- components/st3m/st3m_console.c | 12 +----------- components/st3m/st3m_usb_cdc.c | 1 + 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/components/st3m/st3m_console.c b/components/st3m/st3m_console.c index 12f1b89245..53bf2e86b3 100644 --- a/components/st3m/st3m_console.c +++ b/components/st3m/st3m_console.c @@ -145,16 +145,6 @@ void st3m_gfx_splash(const char *c); // Called by st3m_usb_cdc when it has the opportunity to send some data to the // host. size_t st3m_console_cdc_on_txpoll(uint8_t *buffer, size_t bufsize) { - // I have no idea why this is needed, but it is. Otherwise a large backlog - // of data cuases the IN endpoint to get stuck. - // - // I've spend three days debugging this. - // - // No, I'm not fine. Thanks for asking, though. I appreciate it. - if (bufsize > 0) { - bufsize -= 1; - } - int64_t now = esp_timer_get_time(); xSemaphoreTake(_state.mu, portMAX_DELAY); @@ -400,4 +390,4 @@ static esp_vfs_t _vfs = { .open = &_console_open, .read = &_console_read, .write = &_console_write, -}; \ No newline at end of file +}; diff --git a/components/st3m/st3m_usb_cdc.c b/components/st3m/st3m_usb_cdc.c index a3b12b8222..8bb7999560 100644 --- a/components/st3m/st3m_usb_cdc.c +++ b/components/st3m/st3m_usb_cdc.c @@ -46,6 +46,7 @@ void st3m_usb_cdc_txpoll(void) { for (;;) { uint32_t space = tud_cdc_n_write_available(st3m_usb_interface_app_cdc); if (space == 0) { + tud_cdc_n_write_flush(st3m_usb_interface_app_cdc); return; } -- GitLab