cancel
Showing results for 
Search instead for 
Did you mean: 

How to abort or timeout CDC_Transmit_FS

Yoshi1
Associate III

I am sending with CDC_Transmit_FS by USB CDC, but USB_TransmitCplt_Callback is not called unless the other computer receives it on the COM port.

How do I time out or abort a send?

MCU: STM32L433CCUx

Library Version: STM Cube FW_L4 V1.17.0

4 REPLIES 4

Hello @則幸 �?�岡​ ,

Have you developed your own CDC_Transmit_FS() and USB_TransmitCplt_Callback () functions?

BeST Regards,

Walid

Yoshi1
Associate III

Hello Walid ZRELLI (ST Employee),

CDC_Transmit_FS() has not modified the code generated by STM32CubeMx.

Sorry, ​USB_TransmitCplt_Callback () function was developed by me.

I am calling own USB_TransmitCplt_Callback () from CDC_TransmitCplt_FS() as shown below.

CDC_TransmitCplt_FS() is not called until the COM port is opened on the PC.

CDC_TransmitCplt_FS() is called when the COM port is opened on the PC.

I want to discard data that hasn't been sent for a period of time.

static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
{
  uint8_t result = USBD_OK;
  /* USER CODE BEGIN 13 */
  extern void USB_TransmitCplt_Callback(const uint8_t * Buf, const uint32_t * Len);
  USB_TransmitCplt_Callback(Buf, Len);
  /* USER CODE END 13 */
  return result;
}

Thank you for your kind cooperation.​

Best regards,

Hello @則幸 �?�岡​ ,

If I well understood your question, the following code update should help you :

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;
  }
  
  if((HAL_GetTick() - tickstart ) > TIMEOUT_VALUE)
  {
    return HAL_TIMEOUT;
  }
 
  USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len);
  result = USBD_CDC_TransmitPacket(&hUsbDeviceFS);
  /* USER CODE END 7 */
  return result;
}

Please let me know if this helped you.

BeST Regards,

Walid

Yoshi1
Associate III

Hello Walid ZRELLI (ST Employee),

Thank you for reply.

I'm sorry I didn't explain it well.

The call to CDC_Transmit_FS () is completed immediately, so I don't think the above sample can solve it.

0693W00000CzwDNQAZ.pngThe problem is that the transmitted data remains in STM32L433 MCU forever until COM is opened on the PC side.

I will try to solve it on the PC side.

Thank you for cooperation.

Best regards,

​Yoshi