increase the serial1 buffer size

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: increase the serial1 buffer size

Post 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.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: increase the serial1 buffer size

Post 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.
Attachments
GPS_Time_Baro (2).zip
(50.66 KiB) Downloaded 216 times
Last edited by mrburnette on Sun Jan 10, 2021 1:17 am, edited 3 times in total.
Edogaldo
Posts: 10
Joined: Fri Jul 10, 2020 10:11 pm

Re: increase the serial1 buffer size

Post 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.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: increase the serial1 buffer size

Post 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
Edogaldo
Posts: 10
Joined: Fri Jul 10, 2020 10:11 pm

Re: increase the serial1 buffer size

Post 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.
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: increase the serial1 buffer size

Post 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
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: increase the serial1 buffer size

Post 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.
Edogaldo
Posts: 10
Joined: Fri Jul 10, 2020 10:11 pm

Re: increase the serial1 buffer size

Post 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.
Post Reply

Return to “General discussion”