Handle StatusOut during DataIn Phase. #50
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Windows usb host do not wait for the whole descriptor to be send before moving to the set_address phase.
Instead it enters the status stage by emitting a ZLP on EP0 Out (
Status Out
) instead of sending the expectedDATA IN
request.This can be reproduced by using a
max_packet_size_0
smaller than the device descriptor (typically 18bytes).UsbDeviceBuilder
uses a default value of 8 which triggers the issue.The attached logic analyser trace demonstrates that : small_ctrl_packet.zip (requires saleae logic 2)
Solution in other usb stacks
The linux Kernel
The linux kernel's usb gadget stack accepts a transition to the status phase at anytime during an IN request by priming the OUT EP before starting to process the IN request.
Mbed-OS
Mbed-OS' usb stack stalls the endpoint 0 if it receives an Out packet while processing transfer in the
Receive
direction.See:
USBDevice::_control_out
returns false if it's processing a transfer in aReceive
direction.USBDevice::ep0_out
stalls the endpoint 0 if_control_out
returns false.TinyUsb
TinyUsb hacks the length fields of the request if the descriptor does not fit the endpoint's buffer and if the address is not yet set (aka at the start of the enumeration).
Proposed solution
Accept a ZLP on
EP0 OUT
during aDataIn
transfer as the signal to enter the Status stage of the transfer.Related issues