Documentation for HardwareSerial::addStorageForRead()

Status
Not open for further replies.

cbAMDC

Member
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
 
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...
 
Thank you for the clarification!

We're not planning to use anything but the T4 at the moment, so we should be fine.
 
Status
Not open for further replies.
Back
Top