cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5 USB (CDC) not transmitting data if in exact multiple of 64 bytes

AHugh.2
Associate II

I'm debugging an issue where my application is using device mode USB with CDC-ACM and when I come to transmit a data packet on a bulk IN endpoint that is either 64 or 128 bytes in length, the data is not received by the host until either a different length data packet is tx'd or a certain number of 64 byte tx is done.

System details:

  • STM32U585
  • MCU package 1.2.0
  • Azure RTOS and USBX (6.2.0) as per MCU package.
  • Win 10 host pc

As far as I can tell, everything is going through the HAL/LL layers correctly:

The end point config (DIEPCTL2) has a MPSIZ=0x40 (64 bytes).

When it comes to transmit the data, DIEPTSIZ2 gets set with XFERSIZ=0x40, PKTCNT=1, MCNT=0 and the endpoint is enabled (within USB_EPStartXfer in the HAL).

The ITTXFE interrupt is enabled so the function `PCD_WriteEmptyTxFifo` gets called as expected and `USB_WritePacket()` is called to shift the 64 bytes in to the FIFO.

However, running wireshark on the PC side shows no IN data at all. If I transmit 63 bytes from the device then all is good. If I tx 64 bytes then some other non 64-byte multiple then the PC IN endpoint will get the missing data.

I can't quite see how this is failing so any advise will be good!

1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

Have you heard about "short packet' or "zero length packet" (ZLP) ? Google.

View solution in original post

5 REPLIES 5
Pavel A.
Evangelist III

Have you heard about "short packet' or "zero length packet" (ZLP) ? Google.

AHugh.2
Associate II

I had but had forgotten about it! Thanks - that was exactly it. :thumbs_up: The USBX stack has a setting `UX_DEVICE_CLASS_CDC_ACM_WRITE_AUTO_ZLP` that'll send the ZLP when the data packet is a multiple of max packet size. This #define was commented out in my code.

mohamed.ayed
ST Employee
AHugh.2
Associate II

Thanks. If you look at the equivalent example for the Nucleo-U575 (which is what I based my code on) the UX_DEVICE_CLASS_CDC_ACM_WRITE_AUTO_ZLP macro is commented out. Might be worth updating the example.

https://github.com/STMicroelectronics/STM32CubeU5/blob/main/Projects/STM32U575I-EV/Applications/USBX/Ux_Host_CDC_ACM/USBX/App/ux_user.h

mohamed.ayed
ST Employee

@AHugh.3​  ther ux_user.h that you point from Host CDC ACM application