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

Thread: Documentation for HardwareSerial::addStorageForRead()

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    7

    Documentation for HardwareSerial::addStorageForRead()

    Hello all!

    For my current project I would like to increase the RX and TX buffer size for select UART ports.
    While editing the corresponding HardwareSerialX.c files seems to work I would like to use a more flexible option.

    So I was stumbling upon the functions addStorageForRead() and addStorageForWrite() in the HardwareSerial files. From a number of other threads (like this ) it seems like this is exactly what I need, but I'm a bit unsure on how to use them. Will the received bytes be copied directly to the buffer specified during the call to addStorageForRead() or is the user-defined buffer used internally. Looking at the code in HardwareSerial.cpp I assume the latter is true:

    Code:
    void HardwareSerial::addStorageForWrite(void *buffer, size_t length) 
    {
    	tx_buffer_storage_ = (BUFTYPE*)buffer;
    	if (buffer) {
    		tx_buffer_total_size_ = tx_buffer_total_size_ + length;
    	} else {
    		tx_buffer_total_size_ = tx_buffer_total_size_;
    	} 
    }
    So I assume I simply call the procedure and forget about the buffer before calling HardwareSerial.begin()?

    I would be very greatful for some clarification on that.

    Kind regards,

    Christian

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    6,952
    Again only implemented on T4.x.

    Yes you simply need to allocate the buffer somehow. Could be simple global define, can be malloc and then pass it in.

    The only caveat is that make sure you don't do something like:

    Code:
    void AddMyBuffer() {
       uint8_t myBuffer[256];
       Serial1.addStorageForWrite(myBuffer, sizeof(myBuffer));
    }
    As this uses stack memory and the next thing you call will be allocating that same space again...

  3. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    7
    Thank you for the clarification!

    We're not planning to use anything but the T4 at the moment, so we should be fine.

Posting Permissions

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