cancel
Showing results for 
Search instead for 
Did you mean: 

Why USB CDC_Receive_FS Get Called Multiple times with >64 bytes Packets

Nicolas Felipe
Associate II
Posted on June 19, 2017 at 06:38

My MCU is receiving from Java different packet lenght calls through USB CDC,

When Java Sends 384 bytes the CDC_Receive_FS gets Called 6 times, 384/64 = 6

and its impossible to know when the data has finished because the Java Application send random parameteres and the data lenght is variable,

is there any way to have flow control with the HAL CDC Libraries? or will have to implement some flow control from Java sending Heads and Tail messages.

I have tried almost every interrupt in the HAL libraries but also get called 6 times, for example :

 

in stm32f1xx_hal_pcd.c there is 

/*multi-packet on the NON control OUT endpoint*/

ep->xfer_count+=count;

ep->xfer_buff+=count;

if ((ep->xfer_len == 0) || (count < ep->maxpacket))

{

/* RX COMPLETE */

callBackNumber++;

HAL_PCD_DataOutStageCallback(hpcd, ep->num);

}

but also get called 6 times since the callBackNumber keeps incrementing at that pace.

i have seen this question asked lot of times but vague answers, is there a method to know the RX packets real lenght?

thanks for any helpful answer.

2 REPLIES 2
Zt Liu
Senior III
Posted on June 19, 2017 at 17:46

I had this question too. I am using STM32L053. 

For the moment, I can only add the RX buffer index according to Len 

static int8_t CDC_Receive_FS  (uint8_t* pbuf, uint32_t *Len);

so that the buffer will not be over written. 

Also my protocol with PC must add some length byte information in the header.

Similar problems for CDC_Transmit_FS() too.

If you transmit < 64 bytes, it's OK. 

But if it is >

=

64 bytes(even if it's just 64 bytes), you have to call USBD_CDC_TransmitPacket() several times.

(for 64 bytes transmit, you have to to call it twice! )

Posted on June 19, 2017 at 18:12

great to know because i was going to use other STM32 micros for thinking STM32F1 hal drivers were bugged since is using STM32F1Cube 1.4v (lastest version and last updated in April. 2016) .

in my case i dont have problem with 

CDC_Transmit_FS() i can transfer up to 2000bytes withouth problem and the other program receives it ok in 1 shot but will also transmit a header lenght packet for security.

i dont know is USB HID has flow control or will be good to go.