cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding USB FIFO configuration in the CDC example

SFahr
Associate III

Hi,

I am trying to wrap my head around the correct configuration of the USB FIFOs in USBD_LL_Init().

As far as I understand you need the RX FIFO and one TX FIFO per endpoint .

Lets look at the HID example. There are two endpoints, EP0 + EP1 (the HID).

#define HID_EPIN_ADDR                              0x81U

The FIFO config for FS in USBD_LL_Init() looks like this:

  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 	0x80);
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 	0x40);
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 	0x80);

I take it that the first SetTxFiFo is for EP0 and the second SetTxFiFo is for EP1. Makes sense to me.

Now let look at the CDC example. There are three endpoints, EP0 + EP1 (CDC data) + EP2 (CDC command).

#define CDC_IN_EP           0x81U  /* EP1 for data IN */
#define CDC_OUT_EP          0x01U  /* EP1 for data OUT */
#define CDC_CMD_EP          0x82U  /* EP2 for CDC commands */

However, the FIFO config for FS in USBD_LL_Init() is exactly the same as for the HID:

  HAL_PCDEx_SetRxFiFo(&hpcd_USB_OTG_FS, 0x80);
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 0, 0x40);
  HAL_PCDEx_SetTxFiFo(&hpcd_USB_OTG_FS, 1, 0x80);

How can the CDC example even work, when there are three endpoints, but only two TX FIFOs?

3 REPLIES 3

And does it work?

JW

Hmm maybe because the CDC example actually uses only the "data" endpoint but not "command"?

SFahr
Associate III

You're probably right.

It looks like USBD_CDC_DataIn() and USBD_LL_Transmit() is never called for CDC_CMD_EP, so there is probably never anything sent through this endpoint.

As far as I understand, the communication for CDC_Control_FS() is handled by USBD_CDC_Setup(), which uses EP0.