Skip to main content
Visitor II
July 6, 2021
Question

How to abort or timeout CDC_Transmit_FS

  • July 6, 2021
  • 4 replies
  • 1902 views

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

    This topic has been closed for replies.

    4 replies

    Visitor II
    July 13, 2021

    Hello @則幸 �?�岡​ ,

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

    BeST Regards,

    Walid

    Yoshi1Author
    Visitor II
    July 15, 2021

    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,

    Visitor II
    July 15, 2021

    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

    Yoshi1Author
    Visitor II
    July 19, 2021

    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