AnsweredAssumed Answered

USB Device on STM32F405, lost bytes SOLVED!

Question asked by mennekes.rolf on Mar 27, 2015
Latest reply on Mar 27, 2015 by Kolomaznik.Petr.001
After updating to version 4.7.0, the error appears no more. I'm back to version 4.6.0 and the error will also no longer occur.
Now I'm not sure what it was. Maybe a Windows effect (Shut down the PC and start again), or the complete re-compilation of the project, or...


I have a strange problem here.
Data are transmitted over the function CDC_Transmit_FS.

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
  uint8_t result = USBD_OK;
  /* USER CODE BEGIN 8 */
#define USB_TRANSMIT_TIMEOUT 10000
  uint32_t startTime = HAL_GetTick();

  USBD_CDC_SetTxBuffer(hUsbDevice_0, Buf, Len);   
  do{
    result = USBD_CDC_TransmitPacket(hUsbDevice_0);
  }while((result == USBD_BUSY) && (SYS_DivTick(startTime) < USB_TRANSMIT_TIMEOUT));
  switch(result){
    case USBD_OK:
      result = EC_NoError;
      break;
    case USBD_BUSY:
      MX_USB_DEVICE_Init();
      result = EC_Timeout;
      break;
    default:
      result = EC_Communication;
      break;
  };

  /* USER CODE END 8 */
  return result;
}


This also works well so far, as long as the data is less than 2 ^ 16.
If the amount of data is greater than 2 ^ 16, then two blocks are sent in sequence.

    error = CDC_Transmit_FS((uint8_t*)scopebuffer,50048);
    if(error == EC_NoError) CDC_Transmit_FS((uint8_t*)scopebuffer+50048,50048);

If the first block length is not divisible by 128, then bytes will be lost.
If the length is divisible by 128, then everything works fine.
Has Anyone had similar experiences?

Background Info:
CubeMX in Version 4.6.0
SZM32F405
Own hardware and STMF4Discovery

Outcomes