Skip to main content
Explorer
January 27, 2021
Question

Understanding USB FIFO configuration in the CDC example

  • January 27, 2021
  • 2 replies
  • 1452 views

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?

    This topic has been closed for replies.

    2 replies

    Super User
    January 28, 2021

    And does it work?

    JW

    Super User
    January 28, 2021

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

    SFahrAuthor
    Explorer
    January 29, 2021

    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.