AnsweredAssumed Answered

bug on STM32_USB_Device_Library

Question asked by ln.thierry on Dec 8, 2015
Latest reply on Dec 10, 2015 by 68516
Hi,
I found another bug on USB library for the STM32F3XX (STM32_USB_Device_Library in STM32Cube_FW_F3_V1.3.0).

STM32Cube_FW_F3_V1.3.0\Middlewares\ST\STM32_USB_Device_Library\Core\Src\usbd_core.c

In the usbd_core.c file, the function “USBD_LL_SetupStage” should check the bits [D6:D5] of bmResquest to identify the type request. The function doesn’t work for non standard request type. See USB2.0 specification chapter 9.3 table 9.2.
So when I send to the device request with bmResquest =0xA2 (Dir=In, Type=Class, Recipient=Endpoint) used in USBTMC stack (USBTMC_InitiateAbortBulkOut), this request is badly parsed!
Here is the right code for this function:


/**
* @brief  USBD_SetupStage
*         Handle the setup stage
* @param  pdev: device instance
* @retval status
*/
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) {

    USBD_ParseSetupRequest(&pdev->request, psetup);

    pdev->ep0_state = USBD_EP0_SETUP;
    pdev->ep0_data_len = pdev->request.wLength;

    /* bug should check if bmRequest is standard request type ! */
    /* @see table 9.2 chap 9 of USB Spec ! */
    uint8_t type = pdev->request.bmRequest & USB_REQ_TYPE_MASK;
    switch (type) {
    case USB_REQ_TYPE_STANDARD:
        switch (pdev->request.bmRequest & 0x1F)
        {
        case USB_REQ_RECIPIENT_DEVICE:
            USBD_StdDevReq(pdev, &pdev->request);
            break;

        case USB_REQ_RECIPIENT_INTERFACE:
            USBD_StdItfReq(pdev, &pdev->request);
            break;

        case USB_REQ_RECIPIENT_ENDPOINT:
            USBD_StdEPReq(pdev, &pdev->request);
            break;

        default:
            USBD_LL_StallEP(pdev, pdev->request.bmRequest & 0x80);
            break;
        }
        break;

    case USB_REQ_TYPE_CLASS:
    case USB_REQ_TYPE_VENDOR:
        /* added missing callback ! */
        if (pdev->dev_state == USBD_STATE_CONFIGURED) {
            if (pdev->pClass->Setup != NULL)
                pdev->pClass->Setup(pdev, &pdev->request);
        } else {
            USBD_CtlError(pdev, &pdev->request);
        }
        break;
    }

    return USBD_OK;
}


This bug is also on all firmware.

Outcomes