cancel
Showing results for 
Search instead for 
Did you mean: 

[VCP CDC_Transmit_FS ] how to send bytes packet properly?

Evgeny Popov
Associate III

im having trouble to send a bytes packet with CDC_Transmit_FS function.

For example:

CDC_Transmit_FS((uint8_t*)SendArray1,512);

Doesnt work for me, it sends garbage

But if i sprintf bytes and send them in a loop, it works perfectly, but it sends data in hex string.

	for(i=0;i<512;i++)
{ 
SendArray1[i]  = ByteRead_DataPin(port1);
	sprintf(str,"%02X",SendArray1[i]);
CDC_Transmit_FS((uint8_t*)SendArray1,strlen(str));
}

im using default settings from CubeMX:

uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len)
{
uint8_t result = USBD_OK;
  /* USER CODE BEGIN 7 */
  USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;
  if (hcdc->TxState != 0){
    return USBD_BUSY;
  }
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
  result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
  /* USER CODE END 7 */
  return result;
}

So in the end how can i send the bytes packet?

my mcu is stm32f407

 also how to properly check that Transmit_FS is ready to send data and it doesnt busy

1 REPLY 1
Pavel A.
Evangelist III

> how to properly check that Transmit_FS is ready to send data and it doesnt busy

​You've already found the code:

USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData;

if (hcdc->TxState != 0){

  return USBD_BUSY;

}

Try to send by smaller pieces.

-- pa