zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.9k stars 6.64k forks source link

uac2_explicit_feedback example USB device does not work on Windows #77212

Open prnthp opened 3 months ago

prnthp commented 3 months ago

Describe the bug

Using nRF Connect SDK 2.7.0 with an nRF5340 DK, the example in https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/subsys/usb/uac2_explicit_feedback fails to start as a USB Audio 2.0 device in Windows.

To Reproduce

  1. Have nrf5340DK
  2. Set up nRF Connect SDK 2.7.0 in VS Code
  3. Build and flash uac2_explicit_feedback example

Expected behavior USB device enumerates correctly on Windows and shows up as audio device

Impact Not much, but it would be nice to be able to use USB Audio 2.0 with feedback instead of the USB Audio 1.0 examples

Logs and console output N/A image

Environment (please complete the following information):

github-actions[bot] commented 3 months ago

Hi @prnthp! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

henrikbrixandersen commented 3 months ago

Thank you for reporting this. However - unless you are able to reproduce this issue with upstream Zephyr main - please report issues with the nRF Connect SDK (NCS) on the Nordic Semiconductor DevZone.

tmon-nordic commented 3 months ago

The Code 10 is not telling much. I can reproduce it and the Event Log contains:

The driver could not find a feedback endpoint for an asynchronous data OUT endpoint on device \Device\000000a9.

I wonder why it cannot find feedback endpoint (there is one in the sample).

Changing AS_EXPLICIT_FEEDBACK_ENDPOINT_DESCRIPTOR() to set wMaxPacketSize to 4 instead of 3 solves the issue on Windows. However, this is wrong because Full-Speed feedback endpoint is 3 bytes long, not 4.

Universal Serial Bus Specification Revision 2.0 5.12.4.2 Feedback

[...] In summary, for full-speed endpoints, the Ff value shall be encoded in an unsigned 10.10 (K=10) format which fits into three bytes. Because the maximum integer value is fixed to 1,023, the 10.10 number will be left-justified in the 24 bits, so that it has a 10.14 format. Only the first ten bits behind the binary point are required. The lower four bits may be optionally used to extend the precision of Ff, otherwise, they shall be reported as zero. For high-speed endpoints, the Ff value shall be encoded in an unsigned 12.13 (K=13) format which fits into four bytes. The value shall be aligned into these four bytes so that the binary point is located between the second and the third byte so that it has a 16.16 format. The most significant four bits shall be reported zero. Only the first 13 bits behind the binary point are required. The lower three bits may be optionally used to extend the precision of Ff, otherwise, they shall be reported as zero. [...]

tmon-nordic commented 3 months ago

@mvaneerde Could you perhaps shed more light on why Microsoft UAC2 driver expects asynchronous feedback endpoint to have wMaxPacketSize equal 4 when device is operating at Full-Speed?

tmon-nordic commented 3 months ago

Reported the problem via Feedback Hub: https://aka.ms/AArvnax

udoeb commented 2 months ago

Hi, this is Udo. I wrote the UAC2 driver for MS.

Unfortunately, at full speed, the driver does not support feedback endpoints correctly. This is an issue MS did not discover during testing as FS support was not on their list of requirements. I provided a fix after the driver was released but obviously it never made it into Windows.

If your MCU is limited to FS, you should create an audio class 1 device. You will not gain much from HS anyway. Bandwidth and latency will not improve.