Inconsistent serial output with ESP32-S3 and the TinyUSB CDC device stack
Posted: Tue Oct 01, 2024 9:02 pm
I've been struggling to get serial printing to work consistently using the USB-OTG and the TinyUSB CDC device stack on the ESP32-S3-DevKitC-1 with the ESP32-S3-WROOM-1).
I have narrowed one issue to the minimal code + sdk config provided below. When I delay the task for 3s, the idf_monitor.py sometimes receives a single iteration of text, but then will not print again (I left it for an hour) until I try to send something back by typing. When I type, I get all the built up text at once in bulk - so it is running, but the serial data appears to just not be transmitted. When the delay is set to 2s, it happily prints as expected with with 2s intervals between messages.
I also tried waiting on tud_cdc_connected() and tud_cdc_available(), but both remain false, even while the serial is printing and working and being received with the 2s delay. It seems odd, and is maybe a hint at the problem?
Would anyone be able to point me in the right direction about what is causing this behaviour? It's so basic, I'm sure I'm missing something very obvious, but I've been through the documentation and much deeper in the codebase and I can't figure it out.
The sdkconfig.defaults
I have narrowed one issue to the minimal code + sdk config provided below. When I delay the task for 3s, the idf_monitor.py sometimes receives a single iteration of text, but then will not print again (I left it for an hour) until I try to send something back by typing. When I type, I get all the built up text at once in bulk - so it is running, but the serial data appears to just not be transmitted. When the delay is set to 2s, it happily prints as expected with with 2s intervals between messages.
I also tried waiting on tud_cdc_connected() and tud_cdc_available(), but both remain false, even while the serial is printing and working and being received with the 2s delay. It seems odd, and is maybe a hint at the problem?
Would anyone be able to point me in the right direction about what is causing this behaviour? It's so basic, I'm sure I'm missing something very obvious, but I've been through the documentation and much deeper in the codebase and I can't figure it out.
- #include <stdint.h>
- #include "esp_log.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "tinyusb.h"
- #include "tusb_cdc_acm.h"
- #include "tusb_console.h"
- #include "sdkconfig.h"
- static const char *TAG = "example";
- void use_tinyusb(void *arg)
- {
- const tinyusb_config_t tusb_cfg = {
- .device_descriptor = NULL,
- .string_descriptor = NULL,
- .external_phy = false,
- .configuration_descriptor = NULL,
- };
- ESP_ERROR_CHECK(tinyusb_driver_install(&tusb_cfg));
- tinyusb_config_cdcacm_t acm_cfg = { 0 };
- ESP_ERROR_CHECK(tusb_cdc_acm_init(&acm_cfg));
- ESP_ERROR_CHECK(esp_tusb_init_console(TINYUSB_CDC_ACM_0)); // log to usb
- }
- void app_main(void)
- {
- use_tinyusb(NULL);
- while (true) {
- printf("before...\n");
- //vTaskDelay(pdMS_TO_TICKS(2000)); // Received as expected every 2s to idf-monitor
- vTaskDelay(pdMS_TO_TICKS(3000)); // Sometimes received once, and never again until text sent back through the monitor.
- printf("after\n\n");
- }
- }
Code: Select all
# Increase main task stack size
CONFIG_ESP_MAIN_TASK_STACK_SIZE=7168
# Enable FreeRTOS stats formatting functions, needed for 'tasks' command
CONFIG_FREERTOS_USE_TRACE_FACILITY=y
CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y
# Enable Tiny USB
CONFIG_TINYUSB_CDC_ENABLED=y
# On chips with USB serial, disable secondary console which does not make sense when using console component
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y