This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use nrf5340 as a USB Microphone device?

I want to use nrf5340 as a USB Audio Microphone.

I am taking the help of zephyr/samples/subsys/usb/audio/headphones_microphone sample app, which contains USB Headphone + USB Microphone.

To disable USB Headphone, I am commenting hp_dev related code from main.c and I am modifying the nrf5340dk_nrf5340_cpuapp.overlay as follows:

&usbd {
mic_0 {
label = "MICROPHONE";
compatible = "usb-audio-mic";
feature-mute;
channel-l;
channel-r;
};
};

I have a static 192 byte PCM buffer that I want to continuously send over USB, for which I am using the following code in loop:

struct usb_audio_dev_data *audio_dev_data = mic_dev->data;
struct net_buf *buffer = net_buf_alloc(audio_dev_data->pool, K_NO_WAIT);
memcpy(buffer->data, pcm_buffer, buffer_len);
ret = usb_audio_send(dev, buffer, buffer_len);

But it does not work and the code crashes. 

Please advise.

Related