cancel
Showing results for 
Search instead for 
Did you mean: 

For STM32H563IIK6 USB Virtual configuration hanging in the code.

gatadivijay
Associate II

On Cubex Generated code, we added Virtual Com Port code.

But the code is going to Hard fault handler in USB_ActivateEndpoint. 

 

HAL_StatusTypeDef USB_ActivateEndpoint(USB_DRD_TypeDef *USBx, USB_DRD_EPTypeDef *ep)
{
HAL_StatusTypeDef ret = HAL_OK;
uint32_t wEpRegVal;

wEpRegVal = PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_T_MASK;

 

 

Please can you suggest any thing is wrong.

4 REPLIES 4
Mohamed_AYED
Associate III

Hi @gatadivijay Can you please share with us endpoint PMA configuration ??.

This is the PMA Configuration.

void MX_USB_PCD_Init(void)

{

 

/* USER CODE BEGIN USB_Init 0 */

hpcd_USB_DRD_FS.pData = &hUsbDeviceFS;

/* USER CODE END USB_Init 0 */

 

/* USER CODE BEGIN USB_Init 1 */

 

/* USER CODE END USB_Init 1 */

hpcd_USB_DRD_FS.Instance = USB_DRD_FS;

hpcd_USB_DRD_FS.Init.dev_endpoints = 8;

hpcd_USB_DRD_FS.Init.speed = USBD_FS_SPEED;

hpcd_USB_DRD_FS.Init.phy_itface = PCD_PHY_EMBEDDED;

hpcd_USB_DRD_FS.Init.Sof_enable = DISABLE;

hpcd_USB_DRD_FS.Init.low_power_enable = DISABLE;

hpcd_USB_DRD_FS.Init.lpm_enable = DISABLE;

hpcd_USB_DRD_FS.Init.battery_charging_enable = DISABLE;

hpcd_USB_DRD_FS.Init.vbus_sensing_enable = DISABLE;

hpcd_USB_DRD_FS.Init.bulk_doublebuffer_enable = DISABLE;

hpcd_USB_DRD_FS.Init.iso_singlebuffer_enable = DISABLE;

if (HAL_PCD_Init(&hpcd_USB_DRD_FS) != HAL_OK)

{

Error_Handler();

}

/* USER CODE BEGIN USB_Init 2 */

if(USBD_Init(&hUsbDeviceFS, &Class_Desc, 0) != USBD_OK)

Error_Handler();

 

if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)

Error_Handler();

 

if(USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_CDC_Template_fops) != USBD_OK)

Error_Handler();

 

if(USBD_Start(&hUsbDeviceFS) != USBD_OK)

Error_Handler();

/* USER CODE END USB_Init 2 */

 

}

 

USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)

{

pdev->pData = &hpcd_USB_DRD_FS;

HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x00 , PCD_SNG_BUF, 0x40);

HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x80 , PCD_SNG_BUF, 0x80);

HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_SNG_BUF, 0xC0);

HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, 0x100);

HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, 0x140);

return USBD_OK;

}

 

 

Mohamed_AYED
Associate III

I recommande you to put the snippet code in (Insert/Edit code sample) to be more lisible for other user in community.

Mohamed_AYED_0-1710283767864.png

Secand you can try with endpoints PMA config of STM32G0 since it is the same DRD IP.

https://github.com/STMicroelectronics/STM32CubeG0/blob/11bf550bba048e55fb465842fa0b2d1f13660868/Projects/STM32G0C1E-EV/Applications/USB_Device/CDC_Standalone/USB_Device/Target/usbd_conf.c#L436

I tried second one but it still hangs at same point. I will try fist one now and let you know.