USBX CDC device write with callback

Can anyone help me with an example for USBX write with callback or information on how to configure USBX to register for callbacks? I have seen that USBX provides support to have write with callback. API "ux_device_class_cdc_acm_write_with_callback" is used for this purpose. But don't have much information how to configure USBX stack to use a callback.

I'm using SSP version 1.7.0 for S5 controller.

  • Good day, Shincy!

    Sorry for the late response. Regarding your inquiry, you may want to try samples from this thread.

    Best regards,

    Sai
    RenesasRulz Forum Moderator
    https://renesasrulz.com/
    https://academy.renesas.com/
    en-us.knowledgebase.renesas.com/

  • Hi Shincy-
    Here are the module guides and application projects for the Host and Device CDC-ACM modules. Let us know if these help you:
    www.renesas.com/.../keyword-search.html
  • In reply to Sai:

    Thanks for reply.

    I had a look through the links provided. But I'm looking for a non-blocking solution. In USBX Device stack user guide (r11um0007eu0586_synergy_usbx_device.pdf), it's explaine that writing to a CDC-ACM pipe with callback is possible through api "ux_device_class_cdc_acm_write_with_callback". But there is not much information or example on how to register for this kind of callbacks.
  • In reply to Shincy:

    Hi Schincy,

    I've been discussing this some time ago in this thread: renesasrulz.com/.../how-to-implement-full-duplex-communication-on-usbx-cdc-acm

    There is a project attached to the thread which shows how to achieve what you want (not exactly still).

    In short, USBX CDC-ACM doesn't support callback directly (at least at moment when I studied it). Instead you are supposed to implement 2 separate threads dedicated to the CDC-ACM data send and receive. Threads will block when waiting USB transaction (RX and TX) to complete. You could implement callbacks when thread gets resumed after a transaction gets completed (with OK or ERR status).

    BR,
    Mikhail
  • In reply to mevst:

    Thanks Mikhail.
  • In reply to Shincy:

    Register the callbacks with (this will create 2 internal threads and some other ThreadX objects to handle the reads and writes):-

     

            UINT usb_cdc_write_callback(struct UX_SLAVE_CLASS_CDC_ACM_STRUCT *cdc_acm, UINT status, ULONG length);
            UINT usb_cdc_read_callback(struct UX_SLAVE_CLASS_CDC_ACM_STRUCT *cdc_acm, UINT status, UCHAR *data_pointer, ULONG length);

            UX_SLAVE_CLASS_CDC_ACM_CALLBACK_PARAMETER callback_info;
            /* Set the callback parameter. */
            callback_info.ux_device_class_cdc_acm_parameter_write_callback = usb_cdc_write_callback;
            callback_info.ux_device_class_cdc_acm_parameter_read_callback = usb_cdc_read_callback;

            /* Set the USB CDC to use transmission with callback */
            status = ux_device_class_cdc_acm_ioctl(gp_cdc, UX_SLAVE_CLASS_CDC_ACM_IOCTL_TRANSMISSION_START, &callback_info);

     

    Then do the write with :-

            /* Write the data */
            status = ux_device_class_cdc_acm_write_with_callback(gp_cdc, buffer, (ULONG)cdc_write_size);

     

    The the completion of the write will be signalled by the callback, e.g. ;-

     

    UINT usb_cdc_write_callback(struct UX_SLAVE_CLASS_CDC_ACM_STRUCT *cdc_acm, UINT status, ULONG length)
    {
        UINT ret = UX_SUCCESS;
        SSP_PARAMETER_NOT_USED(length);

        if ((UX_SUCCESS == status) && (gp_cdc == cdc_acm))
        {
            ret = tx_event_flags_set(&g_usb_event_flags, USB_CDC_WRITE_COMPLETE_EVENT, TX_OR);
        }

        return ret;
    }

  • In reply to Jeremy:

    Thanks Jeremy,

    very useful info.
    It looks like now the callbacks are implemented by EL.

    What is the SSP version where it works?

    BR,
    Mikhail
  • In reply to mevst:

    This was introduced in SSP 1.6.0 :-

     

  • In reply to Jeremy:

    This is exactly what I was looking for. Thank you so much Jeremy.