Page 1 of 1

Re: increase the serial1 buffer size

Posted: Sat Jan 09, 2021 10:30 am
by stevestrong
Currently the only way to change the buffer size is to modify the header file you mentioned.
Redefining it in your sketch does not work.

Re: increase the serial1 buffer size

Posted: Sat Jan 09, 2021 2:40 pm
by mrburnette
You can use software serial to create a double-buffer (2 line) scheme of arbitrary length. Ladyada did this with the AVR version of her Adafruit GPS code.

https://github.com/adafruit/Adafruit_GP ... it_GPS.cpp

Code: Select all

Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser) {
  common_init();     // Set everything to common state, then...
  gpsSwSerial = ser; // ...override gpsSwSerial with value passed.
}
The buffers appear as

Code: Select all

    if (currentline == line1) {
      currentline = line2;
      lastline = line1;
    } else {
      currentline = line1;
      lastline = line2;
    }

As Adafruit code has evolved lots since 2014 when I wrote my GPS clock using a Maple Mini, I attached a ZIP with all required file that will compile using Roger's Core and IDE 1.8.13. I seem to remember I hacked both Adafruit and SoftwareSerial at the time.
Sketch uses 51056 bytes (46%) of program storage space. Maximum is 110592 bytes.
Global variables use 5512 bytes (31%) of dynamic memory, leaving 11896 bytes for local variables. Maximum is 17408 bytes.

Re: increase the serial1 buffer size

Posted: Sat Jan 09, 2021 6:24 pm
by Edogaldo
Hi, if I can recall correctly you can pass USART_RX_BUF_SIZE and USART_TX_BUF_SIZE as compiler options via the -D parameter.

Re: increase the serial1 buffer size

Posted: Sat Jan 09, 2021 10:48 pm
by mrburnette
Edogaldo wrote: Sat Jan 09, 2021 6:24 pm Hi, if I can recall correctly you can pass USART_RX_BUF_SIZE and USART_TX_BUF_SIZE as compiler options via the -D parameter.
https://stm32duinoforum.com/forum/viewt ... tml#p41706

but I do not see that it was implemented.
Looking at https://github.com/rogerclarkmelbourne/ ... le/usart.h

Code: Select all

#ifndef USART_RX_BUF_SIZE
#define USART_RX_BUF_SIZE               64
#endif

#ifndef USART_TX_BUF_SIZE
#define USART_TX_BUF_SIZE               64
#endif
My (untried) thinking is to create a new boards.txt entry and set the environmental variable there, using something like
-DUSART_RX_BUF_SIZE nnn

https://github.com/rogerclarkmelbourne/ ... boards.txt

Re: increase the serial1 buffer size

Posted: Sat Jan 09, 2021 11:05 pm
by Edogaldo
mrburnette wrote: Sat Jan 09, 2021 10:48 pmMy (untried) thinking is to create a new boards.txt entry and set the environmental variable there, using something like
-DUSART_RX_BUF_SIZE nnn

https://github.com/rogerclarkmelbourne/ ... boards.txt
Yes, correct.

Re: increase the serial1 buffer size

Posted: Sun Jan 10, 2021 1:14 am
by mrburnette
@Edogaldo,

I seem to remember some concerns about making the buffers long and causing lost interrupts/data corruption ... I cannot find the post, so I could be off on this, 'tis been a while.

In any case, through testing needs to be carried out with buffers larger than default.

Ray

Re: increase the serial1 buffer size

Posted: Sun Jan 10, 2021 8:31 am
by ag123
@ray i've occasionally seen my sketches/firmware crash and i think it is caused by the stack overwriting heap memory. there is only 20k sram on bluepill style mcus after all. i'd guess sometimes with various functionalities integrated together, it is quite possible to run out of memory.
there doesn't seem to be an 'easy' way to detect this, i'm not sure if the memory protection features on the mcu could be used to detect this condition.

Re: increase the serial1 buffer size

Posted: Sun Jan 10, 2021 9:59 am
by Edogaldo
Conflicts between heap and stack could happen, it's to be checked case by case.
Also, if I'm not wrong, the buffers are created for each available serial and not only for the used ones, so this means that the buffer allocated is multiplied by the number of available serials.
This can make more probable memory conflicts.