cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 USB CDC receiving more than 64 bytes

Duy Tran
Associate II

Hello,

I am using the USB CDC of NUCLEO-F767ZI board. MY firmware can transmit and receive OK through the USB CDC. However, I cannot receive more than 64 bytes, only the first 64 bytes are received. The transmission is OK, it can send more than 64 bytes.

I tested with Hercules, Tera Term, Putty and the results are the same.

Do you have any idea what I missed or did I do anything wrong?

Thanks and best regards,

Duy

16 REPLIES 16

Hello Imen,

Thanks for your offer, it is so kind of STMicro Support team.

Please see attached file.

Thanks and best regards,

Duy

Imen.D
ST Employee

Hello,

We confirm that the issue on STM32CubeMx side.

The function CDC_Receive_FS() doesn't use the Len parameter:

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
{
  /* USER CODE BEGIN 6 */
  USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]);
  USBD_CDC_ReceivePacket(&hUsbDeviceFS);
  return (USBD_OK);
  /* USER CODE END 6 */
}

So, using USB CDC cannot receive more than 64 bytes and only the first 64 bytes are received.

This issue is raised internally for fix.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello Imen,

Thanks for your feedback. BTW, will it be available in the next version of SDK?

Will there any temporary fix at the moment?

Best regards,

Duy

Hello @Duy Tran​ ,

Sorry Duy Tran, after more investigation with CubeMx team, it appears that it's no a bug inside CubeMx tool:

static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)

as it's made a callback reception from the stack and the data received is in Buf, the length of the data is in Len, So, it's up to the user to use it.

So, this is a pure CubeMx generation, and CubeMX gives just and entry point and can't

generate the full application, the Core code of CDC_Receive_FS() is

well protected by user tags, this can not be considered as a generation issue.

So it is up to you to complete, change the application code.

Best Regards,

Imen

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen

Hello Imen,

The problem is that *Len never gets more than 64. I checked and *Len = (NumOfReceivedBytes % 64).

If I send 69 then *Len = 5; 80 then *Len = 16;

I am trying to debug in the middleware layer and HAL.

Best regards,

Duy

Hello @Imen DAHMEN​ ,

I checked again, actually it can receive more than 64 bytes, however we cannot count on UserRxBufferFS. Only the first 64 bytes of UserRxBufferFS is used, the remaining bytes will overlap the first bytes. May I ask is it a feature also?

Best regards,

Duy

>  after more investigation with CubeMx team, it appears that it's no a bug inside CubeMx tool:

I apologize, indeed CDC_Receive_FS() should be a callback from the USBD CDC driver to the user.

So it is up to the user to handle the len arg.

@Duy Tran​ : CDC_Receive_FS is called once a data packet is received from host.

64 bytes is the max. size for a FS bulk endpoint, this is why this callback does not deliver more than 64 bytes at once.

Normally all packets in a transfer have same size, the max. size of the endpoint.

The last packet in a transfer can be short (less than 64) or zero length.

If you expect more than 64 bytes, just gather the data from subsequent callbacks.

Try to find more examples on github and other places,

-- pa