title: STM32 USB CDC some data lost with Win 10
body: <p>I use USB device - STMicroelectronics development board. Use firmware, that support usb hardware. Its works as USB serial port.</p>
  <p>On host PC (win10 21H1) i use serial terminal (&quot;Tera Term&quot;) for get data from my device. I use standart windows usbserial driver.</p>
  <p>My device sending data. If data flow is small (1-2-5 kByte/s) - all work fine. But if i speed up (flow about 100 kByte/s or more) - i see data loss.</p>
  <p>I communicated with STMicroelectronics support. We checked issue. We saw USB communication with USB analyzer. We think, than it's windows side problem.</p>
  <p>Also, I use a custom port read utility. Data integrity problem persists.</p>
  <p>In received data i saw lost 64 or 128... multiple of 64 bytes. 64bytes - endpoint size in my case. See linked data for more information.</p>
  <p>I create USB_test project in CubeMx. And add simple code for sending data to PC. Loop data sending if previous CDC transmit complete. Adding delays is unacceptable: firstly, it is not 100% elimination of losses; secondly, it has a bad effect on the bandwidth of the channel.</p>
  <pre><code>//in main() function 
  
  uint8_t is_transmit = 0;
  
  HAL_Delay(5000);
  uint8_t Buf[2048];
  uint8_t k = 48;
  // fill the array with printable characters
  for(uint16_t i=0; i&lt;sizeof(Buf)-2; i++){
      if(k &gt; 100) {
          k = 48;
      }
      Buf[i] = k++;
  }
  // array - is a one string line
  Buf[sizeof(Buf)-2] = '\r';
  Buf[sizeof(Buf)-1] = '\n';
          
      
  while (1)
  {
      if(is_transmit == 0){
          is_transmit = 1;
          //HAL_Delay(1); // add delay on 1 ms reduces the likelihood of losses by an order of magnitude
          CDC_Transmit_FS(Buf, sizeof(Buf));
      }
  }
  </code></pre>
  <p>In CDC_TransmitCplt_FS() i flash is_transmit.</p>
  <pre><code>static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
  {
      ---
      extern uint8_t is_transmit;
      is_transmit = 0;
      ---
  
    return result;
  }
  </code></pre>
  <p>Information from ST support communication and USB analyzer log file.
  <a href="https://drive.google.com/drive/folders/1CvTPfaFGmcFxD4V5zTvsVE6U26DNwG2v?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/drive/folders/1CvTPfaFGmcFxD4V5zTvsVE6U26DNwG2v?usp=sharing</a></p>
  <p>How i fix this issue? I need data flow from device to host 500 kB/s or more.</p>
  <p>Best regards, Andrey.</p>