Go Down

Topic: 64-byte serial receive buffer (Read 695 times) previous topic - next topic

nantais

Hi --

We are evaluating the Due for a project and it all looks great except for the 64-byte receive buffer for serial communications.  I realize the 1.5 code is still in beta and it is a port of the earlier product.  Does anyone know if this buffer is going to be increasing in size before the release?  I know that the past code has had to run on some very limited hardware -- is that going to be the case with 1.5 or is it just for Due and better?  Our project involves a chatty serial protocol running at 115,200, which means we have to poll that buffer every 5 ms or we lose data.  We'd be much more comfortable with another order of magnitude and it definitely seems as though the Due can afford that.  But if 1.5 is eventually going to run on hardware with 2K of SRAM, I can understand the decision to limit to 64 bytes and we'll look for another platform.

Thanks for any advice.

Tom

AWOL

Quote
Does anyone know if this buffer is going to be increasing in size before the release?

Why wait for a release?
You have the source - change it yourself!
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

nantais


Why wait for a release?
You have the source - change it yourself!

Thanks for the suggestion.  That's definitely an option.  I was thinking others might be facing the same problem and that Arduino was looking for beta feedback. 

Graynomad

AFAIK it's just a matter of changing the SERIAL_BUFFER_SIZE #define in HardwareSerial.cpp, however the same value is used for both Tx and Rx so you waste a lot of RAM if your comms is one-sided.

This should really be a parameter or another Serial method call IMO.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

AWOL

Quote
This should really be a parameter or another Serial method call IMO

Certainly a defaulted parameter, agreed.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

nantais


AFAIK it's just a matter of changing the SERIAL_BUFFER_SIZE #define in HardwareSerial.cpp, however the same value is used for both Tx and Rx so you waste a lot of RAM if your comms is one-sided.

This should really be a parameter or another Serial method call IMO.

______
Rob

That makes a lot of sense.  There are two issues that I know of.  The first is that 1.5 doesn't appear to be using a Tx buffer from what I see in the sourcecode.  I might be wrong about that, but at first read it appears to be the case.  The single-byte write() method has a spin lock until the TXRDY status bit is set.  We're working around that by testing TXRDY ourselves in the main loop() and only calling write() when we know the bit is set.  The second issue is that we would need to make sure the variables in the ring buffer are being updated atomically if they're going to be holding values bigger than 255.  That's probably true for the Due, but we would need to be sure.

Tom

Graynomad

#6
Jul 16, 2013, 05:55 pm Last Edit: Jul 16, 2013, 05:57 pm by Graynomad Reason: 1
Quote
The second issue is that we would need to make sure the variables in the ring buffer are being updated atomically

Doesn't look like it.

Code: [Select]
int HardwareSerial::read(void)
{
  // if the head isn't ahead of the tail, we don't have any characters
  if (_rx_buffer->head == _rx_buffer->tail) {
    return -1;
  } else {
    unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
    _rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % SERIAL_BUFFER_SIZE;
    return c;
  }
}


The Due would be the same I assume.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Go Up