Hi,
I'm trying to pass audio data from PDM callback function to a USB device and I'm kind of stuck.
Background:
I'm using the nRF52840-DK board and 2 MP34DT05-A microphones. Since there is no PDM example in the SDK I took the liberty of writing the code from scratch based on the non-legacy PDM driver. It is very similar to I2S in design so didnt take much to make it work. To verify that it works I used fstorage library to save the samples into memory nd then Segger J-Flash to dump contents to file on a windows computer and the WaveSurfer to make sure it is actual audio data. (basically up to date code and applications described here)
IT WORKED
Here is a snippet of the relevant code in my program:
Now, the problem I'm facing is how to pass that data to a USB audio device.
I started with the USB audio device example in the SDK and stripped all the headphones related code since it is irrelevant.
When I looked at the code I could see that the function app_usbd_audio_class_tx_start() that actually passes data to the USB device is called inside the SOF handler of the headphones.
I needed to find a new home for it ..
My naive first attempt was to place it directly inside the PDM handler (where fstorage_write_done() is right now). To cut a long story short - it didnt work, it returns with code 8 (invalid state). So I went to the documentation and it says there that writing can only occur during an SOF event. (and it has a small example here that I tried to use).
I came up with this code (which doesnt work .. same old return code 8 - invalid state):
My question is - how can I pass the data from the PDM callback to the USB device reliably with no errors ?
Remark #1:
In the code snippets I attached the "// ." signify mode code there that I didnt bother to attach.
Remark #2:
I didnt change anything in the definition of the USB microphone which might be a problem.
Especially the following line:
When I connect the board to a Linux machine and look at dmesg output I get a warning/error that max interface should be 1. I guess the 2 and 3 values here are wrong.
Remark #3:
I read in the documentation that the isochroneous USB device can have a maximum buffer size of 1000 bytes, so I use a double buffer of 500 int16_t for the PDM: