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.

TMS320F28379D: [FAQ] TMS320F28379D: Problems with usb lib using

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

hello,

QUESTION: when usb CDC device interrupt program has been triggered and USB_EVENT_RX_AVAILABLE is obtained. 

    The return value of USBDCDCRxPacketAvailable(&g_sCDCDevice) has always been 0.

    I'm sure get the data, because of i get the correct data by USBBufferRead(const tUSBBuffer *psBuffer, uint8_t *pui8Data, uint32_t ui32Length)

    Please help analyze what went wrong. thank you.

uint32_t RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,  void *pvMsgData)
{
    switch(ui32Event)
    {
        //
        // A new packet has been received.
        //
        case USB_EVENT_RX_AVAILABLE:
        {
            uint32_t rx_available = USBDCDCRxPacketAvailable(&g_sCDCDevice);
            break;
        }
        case USB_EVENT_DATA_REMAINING:
        {
            uint32_t rx_available = USBDCDCRxPacketAvailable(&g_sCDCDevice);
          
            return(0);
        }
        case USB_EVENT_REQUEST_BUFFER:
        {
            return(0);
        }
        //
        // We don't expect to receive any other events.  Ignore any that show
        // up in a release build or hang in a debug build.
        //
        default:
#ifdef DEBUG
            while(1);
#else
            break;
#endif
    }
    return(0);
}
  • Hi Chang,

    To debug this further you can dig into the USB library source code located at the below directory. You can import the project into CCS and I think you can even place breakpoints within it to further debug the 'USBDCDCRxPacketAvailable' function during run time. You may need to link the library in a different way to do this however.

    C:\ti\c2000\C2000Ware_2_01_00_00\libraries\communications\usb\f2837xd

    Please see the possible ways the function can return 0 per the below function source code.

    //*****************************************************************************
    //
    //! Determines whether a packet is available and, if so, the size of the
    //! buffer required to read it.
    //!
    //! \param pvCDCDevice is the pointer to the device instance structure as
    //! returned by USBDCDCInit().
    //!
    //! This function may be used to determine if a received packet remains to be
    //! read and allows the application to determine the buffer size needed to
    //! read the data.
    //!
    //! \return Returns 0 if no received packet remains unprocessed or the
    //! size of the packet if a packet is waiting to be read.
    //
    //*****************************************************************************
    uint32_t
    USBDCDCRxPacketAvailable(void *pvCDCDevice)
    {
        uint32_t ui32EPStatus, ui32Size;
        tCDCSerInstance *psInst;
    
        ASSERT(pvCDCDevice);
    
        //
        // Get a pointer to the CDC device instance data pointer
        //
        psInst = &((tUSBDCDCDevice *)pvCDCDevice)->sPrivateData;
    
        //
        // If receive is currently blocked, return 0.
        //
        if(psInst->bRxBlocked || psInst->bControlBlocked)
        {
            return(0);
        }
    
        //
        // Does the relevant endpoint FIFO have a packet waiting for us?
        //
        ui32EPStatus = USBEndpointStatus(psInst->ui32USBBase,
                                         psInst->ui8BulkOUTEndpoint);
    
        if(ui32EPStatus & USB_DEV_RX_PKT_RDY)
        {
            //
            // Yes - a packet is waiting.  How big is it?
            //
            ui32Size = USBEndpointDataAvail(psInst->ui32USBBase,
                                            psInst->ui8BulkOUTEndpoint);
    
            return(ui32Size);
        }
        else
        {
            //
            // There is no packet waiting to be received.
            //
            return(0);
        }
    }

    Best,

    Kevin

  • Hi Kevin,

    thank you,

    i had place breakpoints within the function, and USBEndpointStatus() never return USB_DEV_RX_PKT_RDY.

    28379's usb send data to PC COM is OK by USBDCDCPacketWrite().

    when  PC  send data to 28379 via COM ,  Data can only be read out through USBBufferRead(const tUSBBuffer *psBuffer, uint8_t *pui8Data,  uint32_t ui32Length)

    so, I guess the problem is that the virtual serial port is used as USB communication on my PC, so the endpoint's end state is not obtained.?