cancel
Showing results for 
Search instead for 
Did you mean: 

USB initialization issue on STM32H7 controller

VKute.2
Associate

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?

2 REPLIES 2
Amel NASRI
ST Employee

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.