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.

TM4C1290NCPDT: USBBufferRead

Part Number: TM4C1290NCPDT

I'm trying to understand the use of the USBBufferRead function. Is there

a way to set this up so ulRead is as large as MAX_USB_CDC_PACKET_SIZE (64)?

ulRead = USBBufferRead(&g_psRxBuffer[0], &m_ucUSBInputBuffer[0], MAX_USB_CDC_PACKET_SIZE);

UART_BUFFER_SIZE is set to 256. 128 has also been tried and ulRead is either 8 or 4 respectively.

Free RTOS API allots memory dynamically for m_ucUSBInputBuffer correctly.

However the last few bytes in the 64 byte block are non-zero characters. This is leading

to some garbled printing in the application.

If there is a different way to zero these characters in the 64 byte sequence, other than

increasing ulRead, please let me know.

Thanks,

Priya

  • Hello Priya,

    The USBBufferRead uses the following segment to determine how much to read out:

        //
        // How much data is in the buffer?
        //
        ui32Avail = USBRingBufUsed(&psPrivate->sRingBuf);
    
        //
        // Determine how many bytes we can actually read.
        //
        ui32Read = (ui32Avail < ui32Length) ? ui32Avail : ui32Length;

    Based on your description, it sounds like not all the data is available to read.

    How much data are you sending, and how?

  • Thank you for your reply. 

    The data is bring received from the USB. 

    ulRead = USBBufferRead(&g_psRxBuffer[0], &m_ucUSBInputBuffer[0], MAX_USB_CDC_PACKET_SIZE);

    ulRead is 4.

    UART_BUFFER_SIZE 128

    Is this the way the external processor is sending data through the USB?

    If this cannot be changed, is there anything that can be done with memory locations following these 4 bytes being non-zero?

    The last 4 bytes of the 64 bit USB packet size are printing as garbled data for the Tiva C. The same setup with stellaris hardware does not have these last 4 garbled bytes

    Priya

  • Hello Priya,

    If the last bytes are printing as garbled, that makes me think that the USB application is either not correctly sending or handling receiving data. First I would suggest trying to view the USB lines to see if the garbled data is being transmit if you think there could be a problem on that end. If you know the data would be fine (coming from a known source like a PC), then you'd need to review your application handling for the received data to make sure you are not trying to print more bytes than received.

    As far as ensuring certain memory locations are zero, review your buffer usage and initialization. If it is filled at any point or not initialized to zero and that is an issue, then you could zero it out. But the output should be based on bytes received, and if the USB interface is not sending more than 60 bytes, you should only get indication that you received 60 bytes back and then adjust the output accordingly.