cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 discovery USB microphone - purpose of DCD_EP_Flush function

chupys
Associate II

Hi.

I was working on my small pet-project, trying to develop USB mic on my stm32f4 discovery board. I was successfully completed this project but still not fully understand how it`s working. Function DCD_EP_Flush really confuse me.

My device work as follows. I am start sending sample from mic to usb, when host select appropriate alt setting (when host send SET_INTERFACE with wIndex == 1)

After that my usbd_audio_DataIn func looks like this (a bit simplified version):

static uint8_t  usbd_audio_DataIn (void *pdev, uint8_t epnum)
{
  DCD_EP_Flush(pdev, AUDIO_IN_EP);
 
  /* function, that get`s pointer to buffer with lattest mic`s samples  */
  uint8_t *next = um_handle_in_dequeue(in_handle);
 
  DCD_EP_Tx(pdev, AUDIO_IN_EP, next, in_handle->um_usb_packet_size);
 
  return USBD_OK;
}

Why do I need DCD_EP_Flush here???????

If I correctly understand, usbd_audio_DataIn is calling, when data was transmitted over USB from FIFO buffer. So in that case flushing FIFO buffer is kinda redundant. But when Im trying to remove this function - it is stop working correctly. With help of wireshark I can see that without flushing each usb packet contain only 4 bytes (out of 96).

Does it mean that USB core does not clean FIFO buffer after data was transmitted? Do I have to clean FIFO buffer each time explicitly? Or I miss something?

Thank you

1 REPLY 1
Volodymyr
Associate

Hi, Could you share your project ?