Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: (Simple?) Question on serial buffers? (T4.1)

  1. #1

    (Simple?) Question on serial buffers? (T4.1)

    Historically (years ago) I had an issue which required me to increase the serial buffers on a HW serial port on a T3.5 at the time - and I found some references to changes needed in the HardwareSerial1.cpp file as shown here...

    Code:
    #ifndef SERIAL1_TX_BUFFER_SIZE
    #define SERIAL1_TX_BUFFER_SIZE     250 // number of outgoing bytes to buffer
    #endif
    #ifndef SERIAL1_RX_BUFFER_SIZE
    #define SERIAL1_RX_BUFFER_SIZE     128 // number of incoming bytes to buffer
    (I think they were 64/40(?) by default)

    Anyway - fastforward to today when I am updating a sketch and I happen to look at the https://www.pjrc.com/teensy/td_uart.html page which gives this info about a couple of commands...

    Code:
    Serial1.addMemoryForRead(buffer, size)
    Increase the amount of buffer memory between reception of bytes by the serial hardware and the
    available() and read() functions. This is useful when your program must spend lengthy times performing
    other work, like writing to a SD card, before it can return to reading the incoming serial data.
    The buffer array must be a global or static variable.
    
    Serial1.addMemoryForWrite(buffer, size)
    Increase the amount of buffer memory between print(), write() and actual hardware serial transmission.
    This can be useful when your program needs to print or write a large amount of data, without waiting.
    The buffer array must be a global or static variable.
    I have used it and tested the writebuffer change with availableForWrite() with and without the addMemoryForWrite in the code.

    My question is - Is the historical method of updating the .cpp files for each serial port rendered redundant by the addMemoryForWrite/Read options? I remembered that I had to update the cpp files each time I reinstalled Teensduino in the past so it wasn't a good experience - but before I back out those changes and just use the inline code options I wanted to make sure they are doing the same things as the .cpp file changes.

    Cheers - N

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,408
    Quote Originally Posted by Talkiet View Post
    My question is - Is the historical method of updating the .cpp files for each serial port rendered redundant by the addMemoryForWrite/Read options?
    Yes, these functions were added specifically so you and everyone else needing larger buffers would no longer have to edit the core library source.

    To give credit where credit is due, one of the Arduino developers proposed this API. As far as I know, Arduino has not yet implemented this for any of their products. But it was their suggestion. As I recall, the word "Storage" may have originally been proposed rather than "Memory", but my feeling is the word Storage means non-volatile media like SD cards, flash chips with LittleFS, etc.

    KurtE did nearly all the work of making it actually happen for Teensy.

  3. #3
    Excellent - thanks for the confirmation Paul (and thanks for the work KurtE!) ... I'll back out my changes to the cpp files and use the functions where needed instead.

    Cheers - N

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    27,408
    Here is the place where Martino Facchin originally proposed this idea.

    https://github.com/arduino/ArduinoCore-API/pull/8

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •