kiffie / usbd-audio

Audio 1.0 USB class for usb-device
MIT License
27 stars 5 forks source link

Only every second frame arrives #4

Open JosefUtbult opened 1 year ago

JosefUtbult commented 1 year ago

Hi Stephan. I've been trying out the Audio Class implementation for a while now, and have run into a problem I cant seem to figure out. My devboard only seems to receive every second frame from the host. I have tried with both USB FS and HS boards, but the problem still remains. Every interrupt only occurs once every 2 ms, and the data is only present every 2 ms to. I checked with wireshark on the host, and it says that every frame is transmitted correctly and gets reported as transmitted correctly.

Have you had any similar issue? Thanks in advance.

kiffie commented 1 year ago

I had this or a similar issue on an STM32F446RET. The problem was the USB driver used by the HAL (crate synopsys-usb-otg). I solved it with a small patch. What chip are you using? BTW, I did not experience such problems on PIC32 and RP2040.

JosefUtbult commented 1 year ago

Cool. I've been using a STM32H743ZITx with USB HS. I have also been trying with a STM32F7411RETx on FS.

kiffie commented 1 year ago

Do you mean STM32F411?

In the meantime, I reviewed my patch I created about a year ago. I put it on Github on https://github.com/kiffie/synopsys-usb-otg after rebasing it to the current master.

I can confirm that using the original synopsys-usb-otg has the same issue on STM32F446, i.e. loss of every second ISO packet. The patch fixes this issue for audio output (data flow from the host to the USB device).

Feel free to try it and let me know if it works.

I think the easiest way to test it, is to clone the iso-ep branch and add something like this to Cargo.toml of your program:

[patch.crates-io]
synopsys-usb-otg = { path = "../synopsys-usb-otg" }
JosefUtbult commented 1 year ago

Thanks! Ill try it out. You're a lifesaver!

JosefUtbult commented 1 year ago

It worked! I tried it for both the STM32F411 and the STM32H743, and the patch solved the problem.

I can make some changes in the stm32f4 example and make a pull request. Is it possible for you to explain what the problem was? I'm writing my masters thesis, and kinda need an explanation.

kiffie commented 1 year ago

Great. Does it also work on USB HS?

The issue was caused by the USB hardware checking the LSB (odd/even information) of the frame/micro frame number as indicated in the last SOF packet. The modified synopsys-usb-otg crate toggles the even/odd frame bit in the OTG_DOEPCTLx so that every ISO packet is received. More information can be found in the ST documentation, e.g. ST RM0390, section 31.16.6 "Device programming model".

A PR related to the stm32f4 example is very welcome, of course.

BTW, I am currently thinking about beautifying my quick fix on synopsys-usb-otg and sending a PR to them. Maybe, I will make some commits in my fork.

JosefUtbult commented 1 year ago

Yea it seems to work on HS. The frame rate is still 1 ms though. I'm not sure if its still supposed to be that using HS, or if there is something else acting weird.

I'll fix the PM

kiffie commented 1 year ago

In the meantime, I revised the code on the iso-ep branch and crated a PR, see https://github.com/stm32-rs/synopsys-usb-otg/pull/38.

JosefUtbult commented 1 year ago

Sounds good

JosefUtbult commented 11 months ago

Hey man. Sorry for continuing an issue like this, but I couldnt figure out a better way to get in contact with you.

I'm writing my masters thesis report now, and was wondering if you would like to be mensioned in it? In that case, would you be comfortable with me including your real name, or should I just use Stephan or Kiffeie?

kiffie commented 11 months ago

To cite this crate, you can use Stephan alias "Kiffie" and the URL of the repo: https://github.com/kiffie/usbd-audio.

I wish you success with your master thesis!

JosefUtbult commented 11 months ago

Great. I'll send it to you before I publicise it so you can look it over. Thanks.

kiffie commented 11 months ago

No need to send it to me before publication. But you may post a link to the thesis once published if you want.