2024-03-12 01:14 PM
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.
2024-03-12 01:55 PM
Hi @gatadivijay Can you please share with us endpoint PMA configuration ??.
2024-03-12 02:04 PM
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;
}
2024-03-12 03:50 PM - edited 2024-03-13 02:20 AM
I recommande you to put the snippet code in (Insert/Edit code sample) to be more lisible for other user in community.
Secand you can try with endpoints PMA config of STM32G0 since it is the same DRD IP.
2024-03-12 05:51 PM
I tried second one but it still hangs at same point. I will try fist one now and let you know.