Skip to content

MR: tinyusb_net — sync TX backpressure + thread-safe send_sync#475

Draft
tore-espressif wants to merge 1 commit intomasterfrom
fix/device_ncm_timeouts
Draft

MR: tinyusb_net — sync TX backpressure + thread-safe send_sync#475
tore-espressif wants to merge 1 commit intomasterfrom
fix/device_ncm_timeouts

Conversation

@tore-espressif
Copy link
Copy Markdown
Collaborator

Why

  • NCM busy: do_send_sync used to fail the frame when tud_network_can_xmit was false, returning ESP_FAIL. LwIP can react badly (e.g. TCP stalls). We must not block/spin on the USB task either.
  • Concurrency: One global packet_to_send + stack packet + old handshake was not safe if several tasks called tinyusb_net_send_sync.
  • Timeouts: Needed one clear deadline for “wait for TX” + “wait for deferred xmit done”.

What changed

  • Caller runs tinyusb_net_wait_tx_ready(): poll tud_network_can_xmit(len) under vTaskSetTimeOutState / xTaskCheckForTimeOut, yield + periodic 1 ms delay; on deadline → ESP_ERR_TIMEOUT (no defer).
  • USBD task (do_send_sync): tud_network_xmit only, after assert(tud_network_can_xmit) (debug). No FIFO-full ESP_FAIL from this path.
  • Sync path: sync_mutex + stack sync_tx_job_t + shared sync_done_sem completion; drop event group / old buffer_sema / global packet_to_send. Drain done-sem before defer to avoid a stale Give. Mutex and completion Take use ticks_remaining so one budget covers the whole call.
  • tinyusb_net.h: notes for full-call timeout and ESP_ERR_TIMEOUT. Async behaviour unchanged in design.

TODO

  • Test with esp-idf example tusb_ncm
  • Test with esp-idf example sta2eth

Related

Closes espressif/esp-idf#18374

@tore-espressif tore-espressif added this to the esp_tinyusb v2.2.0 milestone Apr 16, 2026
@tore-espressif tore-espressif self-assigned this Apr 16, 2026
@tore-espressif tore-espressif force-pushed the fix/device_ncm_timeouts branch from 2fa3912 to f98bd76 Compare April 16, 2026 07:50
@tore-espressif tore-espressif removed this from the esp_tinyusb v2.2.0 milestone Apr 30, 2026
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.

ESP32-S3 DWC2: ep_in_count=5 prevents CDC+MSC+NCM composite device enumeration

1 participant