Skip to main content
Visitor II
September 19, 2022
Question

USB initialization issue on STM32H7 controller

  • September 19, 2022
  • 1 reply
  • 1345 views

In latest USB CDC library code in file usbd_cdc.c, USBD_CDC_RegisterInterface() function pdev->pClassData is not getting initialize and due to which we are facing hardfault during port connection.

In earlier version of library code pdev->pClassData was getting initialized in the function USBD_CDC_RegisterInterface().

Attached USBD_CDC_RegisterInterface() function with pdev->pClassData initialized. After this change we are not facing any hardfault issue and USB comunication works smoothly.

please let us know is this initialization is correct or any other modification is needed?

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    September 27, 2022

    Hi @VKute.2​ ,

    Based on the description you provided, this looks like a regression.

    As this is not in my area of expertise, I reported the issue internally to get the confirmation: either what you suggested is the solution or there is another thing.

    Internal ticket number: 135563 (This is an internal tracking number and is not accessible or usable by customers).

    I'll keep you informed.

    -Amel

    Technical Moderator
    September 27, 2022

    Hi @VKute.2​ ,

    I got quickly the answer from our expert.

    In the USB CDC library, PClassData allocation is always performed during the interface init:

    static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
    {
     UNUSED(cfgidx);
     USBD_CDC_HandleTypeDef *hcdc;
     
     hcdc = (USBD_CDC_HandleTypeDef *)USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
     
     if (hcdc == NULL)
     {
     pdev->pClassDataCmsit[pdev->classId] = NULL;
     return (uint8_t)USBD_EMEM;
     }
     
     (void)USBD_memset(hcdc, 0, sizeof(USBD_CDC_HandleTypeDef));
     
     pdev->pClassDataCmsit[pdev->classId] = (void *)hcdc;
     pdev->pClassData = pdev->pClassDataCmsit[pdev->classId];
    ...
    }

    Are you making other modifications on your side?

    Do you remember which library version where the pClassData allocation was done during RegisterInterface?

    -Amel