What is the bare minimum code to get USB CDC working reliable?
Title pretty much asks the question itself, so what is the bare minimium code to get "Comport" working reliable? for now it seems that i can call CDC_Transmit_FS X amount of times before usb is getting locked(Always returning BUSY flag, from next write attempt never recovering from that state before power cycle)
is CDC_Control_FS function i have filled the CDC_SET_LINE_CODING case in a way that the settings are "echoed" back to pc in the CDC_GET..... case, which seems to work.
case CDC_SET_LINE_CODING:
LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
(pbuf[2] << 16) | (pbuf[3] << 24));
LineCoding.format = pbuf[4];
LineCoding.paritytype = pbuf[5];
LineCoding.datatype = pbuf[6];
break;
case CDC_GET_LINE_CODING:
pbuf[0] = (uint8_t)(LineCoding.bitrate);
pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8);
pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16);
pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24);
pbuf[4] = LineCoding.format;
pbuf[5] = LineCoding.paritytype;
pbuf[6] = LineCoding.datatype;
break;the transmit function looks like this
uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 7 */
if (hUsbDevice_ptr == NULL) // just a pointer to the hUsbDevice_FS
return USBD_FAIL;
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
/* USER CODE END 7 */
return result;
}- Enumeration of the device always works reliable and i can connect to it.
- Clock speeds should be okay since Can and UART hardware works flawless, and the enumeration is fine.
- CDC_Transmit_FS works X amount of times, before it always return USBD_BUSY.
