cancel
Showing results for 
Search instead for 
Did you mean: 

May be a bug in STM32F3xx_HAL_Driver?

SAoya.1
Associate

I'm creating serial communication application.

I'm using STM32F303RE and USB CDC interface generated by STM32CubeMX.

I used USBD_CDC_TransmitPacket() for transmitting data from device to PC.

But when the data size == 64*x then read() in PC program didn't respond only on Windows.

when <=63 bytes or >=65 bytes responded correctly.

I used Windows10 and usbser.sys was used as driver.

I investigated what is happened, then found out bulk in transportation is not finished in the driver.

In USB FS mode max packet length is 64bytes so the data will be divided into 64bytes.

Thus the driver have to wait less than 64bytes packet to detect the end of the data.

In stm32f3xx_hal_pcd.c

when the data is 64bytes then send only one 64bytes packet and end transmission.

So I edited the code to send 0 bytes packet when the last packet is 64bytes.

Then read() in PC worked correctly.

I edited in PCD_EP_ISR_Handler() in if ((wEPVal & USB_EP_CTR_TX) != 0U)

------

/* Zero Length Packet? */

if (ep->xfer_len == 0U)

{

----- to

/* Zero Length Packet? */

if (ep->xfer_len == 0U && (ep->xfer_count < ep->maxpacket))

{

-------

Added "&& (ep->xfer_count < ep->maxpacket)"

I'm not sure if it is correct or not.

But now 64*x bytes packet worked correctly in windows/linux/mac.

2 REPLIES 2

Hello @SAoya.1​ 

Could you please share your ioc file to check the issue.

Best regards,

Nesrine

SAoya.1
Associate

Hi

My ioc file is this. But It may work only on my board. (it needs cristal and usb connection and some other components)

But the problem seems to be in STM32F3xx_HAL_Driver so it should reproduce in all CDC (Virtual Port Com) applications.

Do you need code project to reproduce the error on nucleo board? (NUCLEO-F303RE)