2021-11-17 01:08 AM
Hello,
I have an issue with USB CDC in my project. it worked flowless till I tried to send faster.
Fisrt I was using :CDC_Transmit_HS((uint8_t *)pSendBuffer , length); without pb at all.
But if I send with a higer data rate the TxState are continiously busy here:
uint8_t CDC_Transmit_HS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
/* USER CODE BEGIN 12 */
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceHS.pClassData;
if (hcdc->TxState != 0){
return USBD_BUSY;
}
I found some other implementation with a while loop to wait until the frame has been sent, like this :
len = sizeof(UserTxBufferHS);
for (i = 0; i < _Len / len; i++)
{
memcpy(UserTxBufferHS, _Buf, len);
USBD_CDC_SetTxBuffer(&hUsbDeviceHS, UserTxBufferHS, len);
while (1)
{
re = USBD_CDC_TransmitPacket(&hUsbDeviceHS);
if (re == USBD_OK)
{
break;
} else if (re == USBD_BUSY) {
continue;
} else if (re == USBD_FAIL) {
break;
}
}
_Buf += len;
}
But I stay stuck in the while loop.
I have made a lot of tries and I have no moreidea how to manage this problem.
Many thanks for your help
Bertrand
Solved! Go to Solution.
2021-11-17 06:33 AM
How much bandwidth are you trying to push through? If it's a lot, you need to read from the USB port on the PC side fairly frequently so the hardware buffer doesn't fill up. If the hardware buffer fills up, the communication will stop until you do so.
2021-11-17 06:33 AM
How much bandwidth are you trying to push through? If it's a lot, you need to read from the USB port on the PC side fairly frequently so the hardware buffer doesn't fill up. If the hardware buffer fills up, the communication will stop until you do so.
2021-11-17 06:36 AM
Hi TDK,
I was just trying to delete my post.... Indeed the pb was on the host side.
The STM USB was really in busy state.
Sorry for the time spend and thank you for you support.
For Forum admin : it should be deleted. I can't do it myself.
2021-11-17 06:59 AM
Why should it be deleted? It asked a question and the question was answered. The point of forums is so other people can view the answer as well.
You can mark it answered by choosing a reply and clicking "Select as Best".
2021-11-17 07:01 AM
you right.
Bertrand