Skip to content

STM32: USB: USB CDC IN Endpoint stuck forever after receiving Clear feature - endpoint halt request #89990

@ptrcr

Description

@ptrcr

Describe the bug

I have a stm32wb55rg based device with enabled USB CDC, that is connected to PC over a USB hub. After the device reset and successful enumeration in host system, application is opening a port to communicate with the device over CDC. During enumeration process, the device schedules sending the ZLP packet.
Normally, after opening a serial port, the host starts polling the In Endpoint right away, reads the ZLP and communication proceeds without any issues. But sometimes before the host starts polling it sends 'Clear feature - endpoint halt' request first, and then starts polling the IN Endpoint.
This request is handled by calling usb_dc_ep_clear_stall. Underneath, it causes setting the endpoint's status to NAK, which effectively cancels any pending transfer without releasing associated resources, that is the queued ZLP packet transfer and endpoint's write semaphore. As a result, it is impossible to schedule any new transfer, because there is an unfinished transfer that due to NAK status will never be completed.

To Reproduce
This situation seems to happen randomly from around once per 5 to once per 100 following cycles:

  1. Reset the device
  2. Open serial port from host application
  3. Send any message from the device to host over CDC

Expected behavior
Message sent from the device to the host should be read by the application that opened the serial port.

Impact
Unable to perform two way communication with the device. Messages from the host to the device are sent successfully.

Logs and console output
The following screenshot presents logs from the described situation. The host sends request b'0201000082000000' and starts polling IN endpoint, but the status is NAK forever, ZLP packet is not read.
Image

Environment (please complete the following information):
I was only able to reproduce this bug on a PC with Debian GNU/Linux 11 bullseye 5.10.0-28-amd64 and the device connected over a USB hub (reproduces with a few different USB hubs).

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions