cancel
Showing results for 
Search instead for 
Did you mean: 

USB device audio class up or IN stream not working.

MWolt.1
Associate II

Device: STM32F411RE NUCLEO

Hello, I am having some issues with STM USBD AUDIO library. For some reason I cannot get it to stream audio data to a host device in a proper way.

The device is successfully recognized as 2 channel 16 bit microphone by my PC.

When I press the record button in windows recorder or audacity nothing happens.

So far all I know is the USBD_AUDIO_DataIn is not getting called and from what I have read so far this is the function where I am supposed to be handling the sending data to host.

I have been trying to get this working for weeks and I have had it working in the past with the following conditions: I put the LL_Transmit function in the USBD_AUDIO_SOF function. This worked as the audio data is supposed to get polled every 1ms anyway. Then I had the problem that every other packet sent was empty, so I added the LL_Transmit function back into DataIn stage and now my sine wave was being sent perfectly. Which is really weird if you think about it. I cannot imagine that the library was designed to be used this way.

The weird thing is, if I do not use the SOF cb the DataIn stage is also not called.

I tried reading documentation but I just don't get this code. Too many layers too much stuff, and fully implemented for only speakers class so I constantly need to back up my workspace in case I do any "code generation" since I cannot work in the STM pre-approved user code spaces. Honestly I feel like throwing this whole library except the USB descriptors in the thrash. I mean previously I have also found the RM and registers much easyer to work with that STM Libraries and LL/HAL documentation. I'll just tell my boss to screw him and his time constraints. Since i'm not getting anywhere anyway.

Unless anyone here has some experience with this library and could tell me what I am doing wrong.

EDIT:::

Here is a picture of some code where I am trying to send just a single array over and over again.


_legacyfs_online_stmicro_images_0693W00000bhfj6QAA.png 

Here follows a picture of wireshank showing empty packets:


_legacyfs_online_stmicro_images_0693W00000bhfkxQAA.pngAs you can see

all packets are empty.

why?

1 ACCEPTED SOLUTION

Accepted Solutions
MWolt.1
Associate II

If anyone is interested in the solution.

Ignore the Data in stage. Many examples of people who use it but I have encountered many more examples of people who can't get it to work.

Enable SOF

Just count the SOF in the USBD_AUDIO_SOF callback.

From main or whatever, send whatever amount of packets is required to be sent with the USB_LL_Trasmit function, whenever SOF > 0.

***** that we cannot use the interrupts but whatever it's an stm library.

View solution in original post

10 REPLIES 10
AScha.3
Chief II
  • maybe - take a look: - has Audio Class 2.0 (UAC2) device

https://github.com/hathach/tinyusb

If you feel a post has answered your question, please click "Accept as Solution".
MWolt.1
Associate II

Hi thank you for your reply.

I am not using an RTOS (never have before). Also I am using the MP3 encoder from STM which is assembly. Encoding a MP3 frame takes multiple USB frames. I cannot really call the tinyUSB task handler from there.

Lets say I were to use tinyUSB with RTOS. Would it be possible to have the RTOS handle USB while in the encoding function or does it still wait until it returns before handling USB task? I guess I would be able to configure that?

MWolt.1
Associate II

Here is a picture of some code where I am trying to send just a single array over and over again.


_legacyfs_online_stmicro_images_0693W00000bhfj6QAA.png 

Here follows a picture of wireshank showing empty packets:


_legacyfs_online_stmicro_images_0693W00000bhfkxQAA.pngAs you can see

all packets are empty.

why?

AScha.3
Chief II

I never had rtos also. (except at work, OS-9 ) .

tiny-usb needs no rtos:


_legacyfs_online_stmicro_images_0693W00000bhfmeQAA.pngno OS should be good to try.

but for audio device :HAL cube should work.

look:

https://github.com/anonymou8/stm32_usb_audio

https://github.com/STMicroelectronics/fp-aud-smartmic1

https://github.com/JhnW/STM32F411E_Disco_Example_AudioDeviceUSB

https://github.com/bob-01/stm32-usb-microphone

https://github.com/vankubo/STM32_USBAudioCard

https://github.com/catzcod/F746_USB_Audio

https://hackaday.io/project/181868-stm32f4-usb-microphone


_legacyfs_online_stmicro_images_0693W00000bhfypQAA.png

If you feel a post has answered your question, please click "Accept as Solution".
MWolt.1
Associate II

If anyone is interested in the solution.

Ignore the Data in stage. Many examples of people who use it but I have encountered many more examples of people who can't get it to work.

Enable SOF

Just count the SOF in the USBD_AUDIO_SOF callback.

From main or whatever, send whatever amount of packets is required to be sent with the USB_LL_Trasmit function, whenever SOF > 0.

***** that we cannot use the interrupts but whatever it's an stm library.

Youtherone
Associate

Maybe its too late, but i'd like to add my solution, if somebody else will ever suffer with this problem.

I got exactly the same problem and after 4 weeks of sttruggling with it I found out that is an issue of my current latest firmware packages - 1.27.1.

After compiling code with 1.26.0 version everything works fine with DataIn function as it should be.

And what is the difference between them?

JW

vinux
Associate II

i have it running (also after burning way too much time...with 1.28), now on 1.27.

 

it does not work entirely though, but the DATA_IN(in) is atleast called.  Now my data seems to be 'half', but that is a bug to resolve, either an DMA/I2S (in) issue or USB related... time will tell

for the curious, i've added my project below (and future reference)

hi @Youtherone : could you share perhaps an example of your code?

Especially (if needed) relation SOF & DataIn, and a (part of) the descriptor?