This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

USBD_CDC_ACM_DataSend no sending

Hi,

I'm working with uVision 5.15 and RL-USB with RTX to develop a USB CDC application. I used the function USBD_CDC_ACM_DataSend to send data over the USB com port. The application continuously (250ms step) sends a keepalive message through the USB com port to the host, the problem is that if the com port is closed after some messages the USBD_CDC_ACM_DataSend stops to work and also return 0 as byte sent, also opening the connection does not solve the problem. Someone knows how to solve this problem? Is this a RL-USB bug?

Regards

Parents
  • > I'm working with uVision 5.15 and RL-USB

    Sound like you are working on the old RL-USB using the latest MDK-ARM.
    The RL-USB interfaces and implementations had changed a lot at MDK ver5.0
    USBD_CDC_ACM_DataSend() was replaced with USBD_CDC_ACM_WriteData()

    Differences to RL-USB
    http://www.keil.com/pack/doc/mw/USB/html/usb_diffs.html

    I remember we had discussed on a problem of the OUT (host->device) endpoint at buffer full in the CDC of the old RL-USB.
    www.keil.com/.../
    I'm not sure, the IN (device->host) endpoint would also have any problem.

    > if the com port is closed after some messages the USBD_CDC_ACM_DataSend stops to work and also return 0 as byte sent,

    Maybe your PC is a Linux (or Mac) box, which polls the CDC bulk IN endpoint just while the COM port opens. Windows CDC driver always polls the IN endpoint, regardless of open/close of the COM port.

    A couple of workaround suggestions,
    a) Endpoint status
    Your firmware may read out the endpoint status directly from the USB hardware register. This method depends on your MCU, tell us the type number of your MCU for further discussion. While the IN endpoint is still occupied by the last packet, don't call USBD_CDC_ACM_DataSend().

    b) DTR signaling to know open/close of COM port
    In most of OS, PC serial library raises DTR at COM port open, it drops DTR at close. If your library wouldn't, your PC application could explicitly flip DTR signaling at open/close. Your firmware can catch DTR change by USBD_CDC_ACM_PortSetControlLineState() callback. While DTR drops, don't send the heart-beat message.

    Tsuneo

Reply
  • > I'm working with uVision 5.15 and RL-USB

    Sound like you are working on the old RL-USB using the latest MDK-ARM.
    The RL-USB interfaces and implementations had changed a lot at MDK ver5.0
    USBD_CDC_ACM_DataSend() was replaced with USBD_CDC_ACM_WriteData()

    Differences to RL-USB
    http://www.keil.com/pack/doc/mw/USB/html/usb_diffs.html

    I remember we had discussed on a problem of the OUT (host->device) endpoint at buffer full in the CDC of the old RL-USB.
    www.keil.com/.../
    I'm not sure, the IN (device->host) endpoint would also have any problem.

    > if the com port is closed after some messages the USBD_CDC_ACM_DataSend stops to work and also return 0 as byte sent,

    Maybe your PC is a Linux (or Mac) box, which polls the CDC bulk IN endpoint just while the COM port opens. Windows CDC driver always polls the IN endpoint, regardless of open/close of the COM port.

    A couple of workaround suggestions,
    a) Endpoint status
    Your firmware may read out the endpoint status directly from the USB hardware register. This method depends on your MCU, tell us the type number of your MCU for further discussion. While the IN endpoint is still occupied by the last packet, don't call USBD_CDC_ACM_DataSend().

    b) DTR signaling to know open/close of COM port
    In most of OS, PC serial library raises DTR at COM port open, it drops DTR at close. If your library wouldn't, your PC application could explicitly flip DTR signaling at open/close. Your firmware can catch DTR change by USBD_CDC_ACM_PortSetControlLineState() callback. While DTR drops, don't send the heart-beat message.

    Tsuneo

Children