cancel
Showing results for 
Search instead for 
Did you mean: 

USB Device on STM32F405, lost bytes SOLVED!

rm2399
Associate III
Posted on March 27, 2015 at 12:07

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 */

 

&sharpdefine 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

#stm32f4-cube-usb-device
1 REPLY 1
petr239955
Associate III
Posted on March 27, 2015 at 16:39

What version of STM32CubeF4

you are using

?

Version

of STM32CubeF4

changed

also ?