AnsweredAssumed Answered

Losing data over USB with a modified VCP example

Question asked by covran.mislav on Jun 10, 2014
Latest reply on Jun 11, 2014 by covran.mislav

I need to establish USB communication between an STM32F405 device and a PC. STM sends 152 bytes of data every 2.3 miliseconds, but there are also some other events and data that should occassionally be sent in either one or both directions. The problem is, some of those regular 152-byte packets (sometimes after only hundreds, sometimes after tens of thousands of successful packets) lose a chunk. And when I try to send a big 412-byte packet from PC to STM, it always completely loses the front part.

The PC side of the code should be cross-platform and I was looking for something simple to implement (since this is my first USB device) so I just adapted the VCP example code for the STM. That allows me to use Boost Asio library on PC (exact code used is 'CallbackAsyncSerial' from this link:

I removed all the USART code from the VCP example, but I don't believe that's where the problem is. I also changed a few settings: enabled the HS core (in FS mode), increased the buffer size (APP_RX_DATA_SIZE) to 4096 and eliminated the interval between IN transfers (CDC_IN_FRAME_INTERVAL = 0).

Lastly, I enabled the internal DMA. This didn't compile at first because a 'usbd_cdc_Desc' array was missing. I think that's a bug, so I just created it by copying a chunk out of 'usbd_cdc_CfgDesc'. I also don't think 'USB_CDC_DESC_SIZ' is defined correctly.

I would be really grateful if someone could offer assistance. I just don't know where the problem could be.