cancel
Showing results for 
Search instead for 
Did you mean: 

H747 : USB HS , USBD_CDC_TransmitPacket() stucks BUSY

Bertrand1
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

4 REPLIES 4
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".

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.

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".

If you feel a post has answered your question, please click "Accept as Solution".

you right.

Bertrand