Author Topic: Changing the Serial buffer size  (Read 3605 times)

digi_guy

  • Jr. Member
  • **
  • Posts: 87
Changing the Serial buffer size
« on: February 21, 2015, 08:32:14 pm »
In trying to solve memory problems I found a suggestion from Adafruit to change the Serial buffer size. Within HardwareSerial.cpp is a line:
Code: [Select]
#define SERIAL_BUFFER_SIZE 64
This can be changed to 32 bytes or less as a way to free up some much needed space.

Has anyone tried this? What would be the visible results?

In practical terms most of the messages I'm sending and reading are short, except for the two bigges:
Initially I need to read 476 bytes
Code: [Select]
GET /WS HTTP/1.1\r\nHost: localhost:8080\r\nConnection: Upgrade\r\nPrag
ma: no-cache\r\nCache-Control: no-cache\r\nUpgrade: Websocket\r\nOrigin: null\r\
nSec-WebSocket-Version: 13\r\nUser-Agent: Mozilla/5.0 (WindoWs NT 6.3; WOW64) Ap
pleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.99 Safari/537.36\r\nAccept
-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-US,en;q=0.8\r\nSec-WebSock
et-Key: AAAAAAAAAAAAAAAAAAAAAA==\r\nSec-WebSocket-Extensions: permessage-deflate
; client_max_WindoW_bits\r\n\r\n

And I need to write 129 bytes
Code: [Select]
"HTTP/1.1 101 SWitching Protocols\r\nUpgrade: Websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: Ymv66kxgM0FcWaLWlGLwTAI=\r\n\r\n"

Now that I've written this out, does the 64 byte buffer limit the length of my Serial.println messages? I noticed that when memory gets tight it frequently misses lines, often getting the first then the last, or sometimes just the last. This makes me wonder if I should't increase the buffer...

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: Changing the Serial buffer size
« Reply #1 on: February 21, 2015, 08:53:48 pm »
Are you doing serial. or serialUSB. ?

when I was doing serial onthe Pro the buffer was 16. At compile time there was an option for 'pro 32' to double it.  Usb does have more overhead,  but I never looked at shrinking that.

Reading this relates to usb cdc: [url][http://digistump.com/board/index.php/topic,1715.msg7892/topicseen.html#msg7892/url]
« Last Edit: February 21, 2015, 09:03:08 pm by defragster »

digi_guy

  • Jr. Member
  • **
  • Posts: 87
Re: Changing the Serial buffer size
« Reply #2 on: February 21, 2015, 11:54:56 pm »
Just Serial, and in re-reading HardwareSerial.cpp I think it might already be set at 16
Code: [Select]
#ifndef SERIAL_BUFFER_SIZE
  #if (RAMEND < 1000)
    #define SERIAL_BUFFER_SIZE 16
  #else
    #define SERIAL_BUFFER_SIZE 64
  #endif
#endif

This could also explain why sometimes things work and sometimes they don't.

defragster

  • Sr. Member
  • ****
  • Posts: 467
Re: Changing the Serial buffer size
« Reply #3 on: February 23, 2015, 04:24:39 pm »
Yeah - I found it to be 16 in practice, if I stayed away too long the bytes were lost - on the IDE board selector you can ask for it be larger.  Don't have DigiStump software installed just now so I can't say for sure but it went up to 32bytes I think.  I didn't grow it as I found I could buffer and read that and was being held up on pushing out to the OLED as I was doing it.