2023-04-05 07:57 AM - edited 2023-11-20 08:54 AM
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.
Here follows a picture of wireshank showing empty packets:
As you can see
all packets are empty.
why?
Solved! Go to Solution.
2023-04-25 04:14 AM
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.
2023-04-05 10:05 AM
https://github.com/hathach/tinyusb
2023-04-06 07:08 AM
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?
2023-04-06 07:16 AM - edited 2023-11-20 08:54 AM
Here is a picture of some code where I am trying to send just a single array over and over again.
Here follows a picture of wireshank showing empty packets:
As you can see
all packets are empty.
why?
2023-04-06 08:06 AM - edited 2023-11-20 08:54 AM
I never had rtos also. (except at work, OS-9 ) .
tiny-usb needs no rtos:
no 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
2023-04-25 04:14 AM
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.
2023-08-08 07:37 PM
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.
2023-08-08 11:10 PM
And what is the difference between them?
JW
2024-01-01 08:32 AM
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)
2024-01-01 08:33 AM
hi @Youtherone : could you share perhaps an example of your code?
Especially (if needed) relation SOF & DataIn, and a (part of) the descriptor?