cancel
Showing results for 
Search instead for 
Did you mean: 

Virtual_COM_Port Sending 0x40 bytes to PC problem on STM32F107RCT6

denlok
Associate II
Posted on July 01, 2011 at 21:56

Hello! I did try to use Virtual COM port project from archive STM32_USB-FS-Device_Lib_V3.3.0, loaded from site. But have problem - when MCU do sending ''bytes string'' from MCU to PC with length 0x40, 0x80, 0xC0 - PC didn't receive anything. If MCU do sending 0x3F, 0x41 bytes or other except ''maxlength'' - all is okey, PC will receive bytes with success! One else - If MCU did send ''single string'' with 0x40 bytes length and (after pause) send some else bytes - PC will receive old 0x40 bytes with these some else bytes! Can you are check it on your testboard?

#usb
2 REPLIES 2
bernhard239955_st
Associate II
Posted on July 04, 2011 at 17:23

Hello Denis,

it seems that 0x40 is Your endpoint buffer size.

The host recognizes the end of a transaction when a pakage with ''less than buffer size'' data is received. (This is an USB protocol issue.)

If You are sending a multiple of your endpoint buffer size You must send a empty pakage after Your last transaction to show the host that Your transaction is complete now.

I think the second problem You mentioned should be cleared with that, too.

Kind regards

bgl

denlok
Associate II
Posted on January 07, 2012 at 21:38

Hello!

Big thanks for answer!!! Best solution is changing some in UsbAsyncXfer procedure. It must be looks as

uint16_t USB_Tx_length =0; // - move it outside function to save last TX packet data length
void Handle_USBAsynchXfer (void)
{
uint16_t USB_Tx_ptr =0;
if(USB_Tx_State != 1)
{
if (USART_Rx_ptr_out == USART_RX_DATA_SIZE)
{
USART_Rx_ptr_out = 0;
}
if(USART_Rx_ptr_out == USART_Rx_ptr_in)
{
USB_Tx_State = 0;
if(USB_Tx_length == VIRTUAL_COM_PORT_DATA_SIZE) // èñïðàâëÿåì êîñÿê ñ ïîñûëêîé 0x40 áàéòîâ
{ USB_Tx_length =0; 
goto SendZeroPacket;
}
return; // transmitt end
}
if(USART_Rx_ptr_out > USART_Rx_ptr_in) /* rollback */
{
USART_Rx_length = USART_RX_DATA_SIZE - USART_Rx_ptr_out;
}
else
{
USART_Rx_length = USART_Rx_ptr_in - USART_Rx_ptr_out;
}
if (USART_Rx_length > VIRTUAL_COM_PORT_DATA_SIZE)
{
USB_Tx_ptr = USART_Rx_ptr_out;
USB_Tx_length = VIRTUAL_COM_PORT_DATA_SIZE;
USART_Rx_ptr_out += VIRTUAL_COM_PORT_DATA_SIZE; 
USART_Rx_length -= VIRTUAL_COM_PORT_DATA_SIZE; 
}
else
{
USB_Tx_ptr = USART_Rx_ptr_out;
USB_Tx_length = USART_Rx_length;
USART_Rx_ptr_out += USART_Rx_length;
USART_Rx_length = 0;
}
USB_Tx_State = 1; 
SendZeroPacket:
USB_SIL_Write(EP1_IN, &USART_Rx_Buffer[USB_Tx_ptr], USB_Tx_length); 
} 
}