Question
USB CDC Bug in CubeMX firmware
Posted on April 11, 2014 at 10:07
Hey everybody,
in order to initialize a working Virtual Com Port with CubeMX on the STM32F4 Discovery, I had to changepdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
topdev->pClassData = (void *) USBD_malloc(sizeof (USBD_CDC_HandleTypeDef));
Without the type cast pClassData would always be null, which will make the parent function (USBD_CDC_Init in usbd_cdc.c) return before initializing the interface. Btw I used firmware 1.1.0.EDIT: Sorry, that was too fast. This line was actually not the root cause, it was the following line in USB_CDC.h &sharpdefine CDC_DATA_HS_MAX_PACKET_SIZE 512Changing that value to 256 made it work for me now. In case anyone is interested, here's a small code example for a vcp mirror. Add this code to CDC_Receive in usb_cdc_if.c
static uint8_t buff_RX[256];
static uint8_t buff_TX[256]; int i = 0; for (i = 0; i < *Len; i++) buff_TX[i] = buff_RX[i]; USBD_CDC_SetTxBuffer(&hUsbDeviceFS, &buff_TX[0], *Len); USBD_CDC_TransmitPacket(&hUsbDeviceFS); USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &buff_RX[0]); USBD_CDC_ReceivePacket(&hUsbDeviceFS);Also you will have to add
extern USBD_HandleTypeDef hUsbDeviceFS;
to this file.
#usb #cdc #cdc #cdc #cdc_receive_fs #full-echo #usb-cdc #vcp #vcp