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.

TM4C1294KCPDT: USB ring buffer question

Part Number: TM4C1294KCPDT

Hello, 

   Im trying to use a USB ring buffer  for some data coming in through CAN. I can initialize it to any size I like ( i need around 512) and all is well. But, if i try to add data past 64 i get a fault. 

Is there a hard limit coded in somewhere that prevents the index from exceeding 63? 

  • Hi Patrick,

      Can you show your code where you specify the ring buffer size to 512 and how you are adding data to the ring buffer. With more information, it is easier for our USB expert to comment. 

  • ok. i will get to that.

    but for now , there is no hard limit on the USBRingBuffer? It is like any other data construct and limited only by memory and smart programming?

    Any overflow,under flow,indexing issues, etc.  are likely code related.

  • Hi Patrick,
    The Ring buffer is supposed to be a software based data structure that uses a fixed size buffer. The size should be limited by the amount of memory.

    Is it that you try to reuse the USB ring buffer implementation for the CAN data reception? I didn't read your question carefully last night. If this is the case, you will need to do some debugging on your own. I would not advice you reusing the USB ring buffer for other peripherals as we have not seen anyone doing as such. If you can get it to work for other peripherals that is great and you can share with the community. With that said, it may be easier if you handle the ring buffers as part of your application. 

  • finally getting back to this

    //declarations

    #define RB_SIZE 64
    uint8_t incoming_message[RB_SIZE];
    tUSBRingBufObject incoming_traffic_buffer;

    in main I run:

     USBRingBufInit(&incoming_traffic_buffer,incoming_message,RB_SIZE);

    an example of the write into the buffer would be 

     USBRingBufWrite(&incoming_traffic_buffer,(incoming.pui8MsgData+1),(incoming.ui32MsgLen-1) );

    an example of reading would be:

    USBRingBufRead(&incoming_traffic_buffer,ReadServiceResponse,incoming_message_length);

     

    The write and read is done in one transaction. i.e request data, get data from machine, put into buffer, read out from buffer and act. 

    the ring buff made it quite easy until i needed to accept some larger xmissions. As long as the above #define RB_SIZE is 64 or less i have no problems

    raise that to 65 or greater and it all crashes. I can see nothing fundamentally wrong with the above statements. Any help would be greatly appreciated. 

    Pat

     

     

     

  • Hi Pat,
    Can you try to increase the stack size, perhaps double your current stack size? Will you see any difference? What is your stack size?
  • tried that. no luck. 

    I cab only conclude I have some more insidious thing happening in my code. some boundary error, memory leak, etc. 

    going to have to try a re-write. Might be the end on the USBRingBuffer. ugh 

  • Hi Patrick,
    Please do share with the community your findings and your new solution. I'm sure it will benefit people looking for the same solution. I will close the thread for now. If you have new question please open a new thread. You can reply back to this thread later on when you have your new solution that you want to share with the community.
  • Hi Patrick,

    patrick murphy said:
    cab only conclude I have some more insidious thing happening in my code. some boundary error, memory leak, etc

    As Charles seemed to advise please use (ringbuffer.c) driverlib tools folder. USBRingBuffer() is linked to the USB library layers and meshes between the composite USB device struct supporting 64 byte packets. The other buffer module can easily handle 512 byte packets  ;-)