cancel
Showing results for 
Search instead for 
Did you mean: 

A potential bug in USB VCP example in STM32_USB-Host-Device_Lib_V2.1.0

jjackbauer7
Associate III
Posted on February 05, 2014 at 11:37

Hi all,

I a using an STM32F407 device with ST standard library and USB lib.

In Handle_USBAsynchXfer() function in usbd_cdc_core.c file:

There is a potential bug when roll-back occurs.

Two pointers are used:

APP_Rx_ptr_in: is incremented when data received over UART

APP_Rx_ptr_out: is incremented when received data over UART are sent over USB

Let's have an example:

if APP_Rx_ptr_in = 3 and APP_Rx_ptr_out = 2047

==> this means that I have received 4 data over UART (I have to send them over USB)

But as states the code below if APP_Rx_ptr_out > APP_Rx_ptr_in, the size is

APP_RX_DATA_SIZE - APP_Rx_ptr_out => 2048 - 2047 = 1 !!

I think it should be (APP_RX_DATA_SIZE - APP_Rx_ptr_out) + APP_Rx_ptr_in

What do you think?

#usb-cdc-vcp
3 REPLIES 3
magnus2399
Associate
Posted on February 06, 2014 at 01:38

The way I've understood it from spending hours trying to understand it fully (a brief comment describing the data structures and program would sure have helped) is that APP_Rx_length is not supposed to indicate the total amount of data waiting to be sent but rather the max amount of data that can be sent without wrapping around the end of the buffer (since the code actually copying the data to the USB peripheral does not handle that case). USB_Tx_length is then calculated as the minimum of APP_Rx_length and CDC_DATA_IN_PACKET_SIZE so it may not even end up handling all bytes to the end of the buffer in one ''cycle''.

So your remaining 3 bytes will be handled once the first one at the end of the buffer is sent. This could of course hurt transfer speed by using two USB packets for data that could fit in one but it's insignificant in practice since there will be no stray bytes at the end of the buffer if you use the full bandwidth (there will always be > CDC_DATA_IN_PACKET_SIZE data in the buffer when this code is executed).
epataky
Associate II
Posted on May 29, 2014 at 23:27

anyone know how to send even 1 byte over usb to the pc? their application only sends over uart

Posted on May 30, 2014 at 00:51

Isn't it all pretty much encapsulate around the USART functions/interrupts that currently map to a physical serial port rather than the true virtualization you seek?

Create some input/output FIFO buffering, and map that to the DataRx / DataTx type functions.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..