Hello, I have implemented the code for the USB VCP, but when debugging the code
the "pdev->pClassData" is always null (0). Where is this class initialized?
code line : USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-17 7:16 AM
Cube MX 5.6.1 generated code:
void MX_USB_DEVICE_Init(void)
{
/* USER CODE BEGIN USB_DEVICE_Init_PreTreatment */
/* USER CODE END USB_DEVICE_Init_PreTreatment */
/* Init Device Library, add supported class and start the library. */
if (USBD_Init(&hUsbDeviceFS, &FS_Desc, DEVICE_FS) != USBD_OK)
{
Error_Handler();
}
if (USBD_RegisterClass(&hUsbDeviceFS, &USBD_CDC) != USBD_OK)
{
Error_Handler();
}
if (USBD_CDC_RegisterInterface(&hUsbDeviceFS, &USBD_Interface_fops_FS) != USBD_OK)
{
Error_Handler();
}
if (USBD_Start(&hUsbDeviceFS) != USBD_OK)
{
Error_Handler();
}
/* USER CODE BEGIN USB_DEVICE_Init_PostTreatment */
/* USER CODE END USB_DEVICE_Init_PostTreatment */
}
to send data this is implemented
while (1)
{
/* USER CODE END WHILE */
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &buffer[0], sizeof(buffer));
USBD_CDC_TransmitPacket(&hUsbDeviceFS);
HAL_delay(1000);
/* USER CODE BEGIN 3 */
}
- Labels:
-
USB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-17 4:46 PM
> Where is this class initialized?
pdev->pClassData is initialized when you call USBD_RegisterClass.
If it is 0 after successful return from USBD_RegisterClass, you probably have memory corruption.
-- pa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-18 7:02 AM
Rex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-18 8:22 PM
This field is only populated after the PC successfully enumerates the device, which is not instant. It also uses malloc, which is probably not what one would expect.
Typically putting HAL_Delay(500) prior to using the USB functions works, although it's not an elegant solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-18 8:39 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-19 5:14 AM
If you use freeRTOS, also take a look here (in case of memory corruption...) :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-19 6:31 AM
Rex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-19 6:32 AM
Thanks for the hint
Rex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-19 6:33 AM
I will give it a shot.
Rex
