This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using uDMA with USB CDC class Driver

Other Parts Discussed in Thread: TM4C123GH6PM

Hello,

I want to incorporate uDMA capability in transmitting and receiving data through the USB CDC class driver. TivaWare™ USB Library   lists functions for DMA access. However, it is not clear how to use these functions to setup uDMA enabled data transfer with the CDC class driver. More specifically, I have following questions:

1. Is it possible to combine uDMA with the CDC class driver?

2. The optional USB Tx/Tx buffers be used or not?

3. How to handle the Control, Receive, and Transmit events? The procedure to use the CDC class driver says  that the user must have interrupt handler functions for for respective category of events. The uDMA will have its own interrupt handler. What type of interaction be established between the CDC class driver handlers and uDMA handler.

Kind regards

Jatala

  • 1. Is it possible to combine uDMA with the CDC class driver?


    In another post, you said you are working on TM4C123GXL (TM4C123GH6PM)
    TM4C123 family has restriction on uDMA application to USB FIFO,

    18.3.2 DMA Operation (TM4C123GH6PM datasheet)
    the size of the μDMA transfer must be restricted to whole multiples of the size of the USB FIFO. Both read and write transfers of the USB FIFOs using μDMA must be configured in this manner. For example, if the USB endpoint is configured with a FIFO size of 64 bytes, the μDMA channel can be used to transfer 64 bytes to or from the endpoint FIFO. If the number of bytes to transfer is less than 64, then a programmed I/O method must be used to copy the data to or from the FIFO.

    In this reason, it isn't possible to apply USB DMA to current TivaWare CDC implementation, which exchanges free-size packets. But if you would simplify the CDC device class driver, you could apply uDMA under above restriction.

    2. The optional USB Tx/Tx buffers be used or not?


    tUSBBuffer objects (usbbuffer.c) are used.

    Tsuneo

  • Thanks Tsuneo. You have pointed in the right direction.

    1. Yes indeed I am working on TM4C123GXL board.

    2. The CDC class driver sends data in packets of maximum size of 64bytes (pp#59). When using uDMA, I can set the arbitration size accordingly.

    3.The optional USB Tx/Tx buffers be used or not? "tUSBBuffer objects (usbbuffer.c) are used" What I am trying to figure out is: do the use of USB TX/RX buffers allowed with the uDMA access? 

    4. How to handle interrupts in the uDMA context? The CDC class driver instructs to use the 'USB0DeviceIntHandler' for the USB device (pp#168), which acts as "the main USB interrupt handler entry point for use in USB device applications. This top-level handler will branch the interrupt off to the appropriate application or stack handlers". As I understand, the 'USB0DeviceIntHandler' pass events to the control, receive, and receive events handler functions (2.7.2 Using the CDC Device Class Driver). When using DMA, I need to have a DMA interrupt handler for the USB peripheral.   Given this context, should I register the DMA interrupt handler and leave out 'USB0DeviceIntHandler'. Do I still need to register interrupt handlers for the control, receive, and transmit events.

    5. To setup DMA transfer with the USB port, I suppose, only the APIs given in 5.6 Internal USB DMA Functions shall be used?

    KR

    Jatala

  • 2. The CDC class driver sends data in packets of maximum size of 64bytes (pp#59). When using uDMA, I can set the arbitration size accordingly.

    ???
    Did you really read above excerption from the data sheet?
    It tells just 64 bytes of packet is allowed, not arbitrary size.

    Tsuneo
  • probably we are talking about two different things. I am referring to CDC class driver. When a user sends data using CDC: the user can write data (USBBufferWrite or directly into the buffer) of arbitrary size to object of  'tUSBBuffer'; however, the driver breaks it down into packets with maximum size of 64 bytes. Alternatively, if no buffers are used, the user can write data in blocks (USBDCDCPacketWrite) where each block cannot be more than 64 bytes long. In either case, whenever a packet is written, the CDC driver reports 'USB_EVENT_TX_COMPLETE' event to the Tx events handler.

    Jatala

  • The "TX" data flow of the original usb_dev_serial appears just like,

      USBBufferWrite()     USBDCDCPacketWrite()
    UART -------> ring buffer -------> USB endpoint FIFO

    Which one, USBBufferWrite() or USBDCDCPacketWrite(), would you like to modify using uDMA?
    Your descriptrion mixes them up.

    A) USBBufferWrite() is your target
    Depending on your data source,
    A-1) a peripheral (replacing above UART with)
    uDMA should be bound to the peripheral

    A-2) a buffer
    uDMA is configured for "software" triggered memory-to-memory DMA

    In either case, there is nothing to do with USB DMA APIs.


    B)  USBDCDCPacketWrite() is your target
    tUSBBuffer object doesn't always write 64-bytes packet using USBDCDCPacketWrite().
    Your options are twofold,

    B-1) Just for 64-bytes packet, uDMA is applied using USB DMA APIs.
    For other packet size, the original USBDCDCPacketWrite() is called as it is.

    B-2) Modify just the last data transfer loop in (MAP_)USBEndpointDataPut()
    "programmed I/O method" by original USBDCDCPacketWrite() is reserved.
    The data transfer loop (below) in (MAP_)USBEndpointDataPut(), which is called by USBDCDCPacketWrite(), is replaced using "software" triggered DMA.

    \TivaWare_C_Series-2.1.0.12573\driverlib\usb.c
    
    int32_t
    USBEndpointDataPut(uint32_t ui32Base, uint32_t ui32Endpoint,
                       uint8_t *pui8Data, uint32_t ui32Size)
    {
        ...
        ...
        //
        // Write the data to the FIFO.
        //
        for(; ui32Size > 0; ui32Size--)     // <----- replace this loop with uDMA
        {
            HWREGB(ui32FIFO) = *pui8Data++;
        }
    
        //
        // Success.
        //
        return(0);
    }


    Which option are you talking about?

    Tsuneo

  • Hi Tsuneo,

    If I have understood you well, the DMA in TM4C123GXL

    1. Cannot be implemented on top of the USB CDC class driver API

    2.  Have to be implemented at the  USB driver level

    Please see if the above statement is correct.

    About the USB packet-size, I do understand the constraints. In my application, I only use USB0 for data transfer b/w the host and the device (TM4C123GXL), and that means I do  not use redirection of data through the UART<-->USB like is done in usb-dev-serial example. 

    Many thanks

    Jatala