cancel
Showing results for 
Search instead for 
Did you mean: 

USB transfer IN problem on stm32g0bx when length is multiple of 64 bytes

GPREV.1
Associate II

I am using usb hal library.

My problem is when the transfer (IN) is complete if the transfer is a multiple of 64 bytes, I don't get a callback on CDC_TransmitCplt_FS() otherwise I get a callback.

At the end of the transmission, the transfer is correct and is normally done on the host side.

In the function: USBD_CDC_DataIn() in usbd_cdc.c

A test seems to create the problem:

if ((pdev->ep_in[epnum & 0xFU].total_length > 0U) &&
((pdev->ep_in[epnum & 0xFU].total_length % hpcd->IN_ep[epnum & 0xFU].maxpacket) == 0U))

the function does not call the TransmitCplt() callback in this case.

I would like to know if it is normal not to call the TransmitCplt() function if the length of the transfer is a multiple of 64 bytes and how to process 64 bytes multiple length transfer_IN complete callback or another solution to process the end of transmission in all cases.

 

 

3 REPLIES 3
TDK
Guru

Most likely a bug which hasn't yet been fixed. See here for issue and fix:

https://community.st.com/t5/embedded-software-mcus/bug-cdc-does-not-transmit-packets-which-length-is-an-exact/td-p/257267

But possibly it has been fixed in the latest HAL library.

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

I think in the bug you reference, packets are not  transmit.

In my case the packets are transmitted to the host but at the end of the transmission the device never calls the transmitCplt callback.

I found a solution; I never transmit a length multiple of 64 bytes. In this case I add 1 byte to the packet but that's not a good solution, it's just a workaround.

MAISS.1
ST Employee

Hello GPREV.1,

We have tested the FW from our side and it works correctly.

You can try to send packets of 128 bytes (multiple of 64 bytes) in loop mode:
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*)&UserTxBufferFS[0], 128);
USBD_CDC_TransmitPacket(&hUsbDeviceFS);

Thanks.