Page 1 of 1

Serial Buffer Size - How to adjust

Posted: Fri Feb 21, 2025 2:04 pm
by timdelta
Hi

I'm running an STM32F407VET using UART to another uC (on same PCB) and would like the option to change the buffer from 64 bytes to 256.

I've tried to follow the guidance at https://github.com/stm32duino/Arduino_C ... uffer-size

What i have specifically done is - added another file in my project folder, "hal_conf_extra.h"
- inside that I've put the following only (I haven't put anything else like #include "Arduino.h" for example):

if !defined(SERIAL_TX_BUFFER_SIZE)
#define DSERIAL_TX_BUFFER_SIZE=256
#endif
#if !defined(SERIAL_RX_BUFFER_SIZE)
#define DSERIAL_RX_BUFFER_SIZE=256
#endif[/code]

in my .ino i have added:

#include "hal_conf_extra.h"

In my setup() I defined my serial (that works fine, just the buffer is a little smaller than I'd like) with:

HardwareSerial ESPSerial(PC11, PC10); //Rx, TX pins from/to ESP32

When I use the Arduino IDE debugger, under Variables - Global - ESPSerial - Stream _rx_buffer still shows [64], and so does tx.

Any ideas where I am going wrong? Am I defining the 256 to a different serial perhaps?

Re: Serial Buffer Size - How to adjust

Posted: Fri Feb 21, 2025 3:28 pm
by fpiSTM
Syntax is not correct remove the D and replace the = by a space....

Or copy the code from the wiki and replace 64 by 256.

Re: Serial Buffer Size - How to adjust

Posted: Fri Feb 21, 2025 5:17 pm
by timdelta
Many thanks... It seems obvious now you pointed it out :oops:

Changed to:

#if !defined(SERIAL_TX_BUFFER_SIZE)
#define SERIAL_TX_BUFFER_SIZE 256
#endif
#if !defined(SERIAL_RX_BUFFER_SIZE)
#define SERIAL_RX_BUFFER_SIZE 256
#endif

Uploaded and tested, but the buffer still shows as 64 in the debugger...

I've even tried editing the HardwareSerial.h in the core and that doesn't change it either :(

Any other ideas please?

Re: Serial Buffer Size - How to adjust

Posted: Mon Feb 24, 2025 6:00 am
by ozcar
This is not something I have ever done before, but I just tried to override the HardwareSerial buffer sizes and it seemed to work for me. Well, I never have much luck with getting debugging to work using the Arduino IDE, so I had to resort to other means to see that the override was working.

I can understand why the sizes are only set in HardwareSerial.h if they are not already defined. I'm not so sure about using the same #if !defined logic in hal_conf_extra.h, but I suppose the intention is that build_opt.h can always override the other two. You did not mention build_opt.h, but if you happen to have that as well, and that sets the buffer sizes to 64, then that could explain what you are seeing.

Re: Serial Buffer Size - How to adjust

Posted: Mon Feb 24, 2025 1:18 pm
by timdelta
Thanks everyone, tried again today and the combination of changing HardwareSerial.h and hal_conf_extra.h seems to have cracked it :D

Re: Serial Buffer Size - How to adjust

Posted: Mon Feb 24, 2025 1:40 pm
by fpiSTM
You don't need to change the HardwareSerial.h.
Maybe you met a Arduino IDE cache issue.
And of course no need to add the:

Code: Select all

#if !defined(SERIAL_*_BUFFER_SIZE)

Re: Serial Buffer Size - How to adjust

Posted: Mon Apr 28, 2025 8:25 am
by timdelta
Thanks for the additional comment - on a different PC it works with only the hal_conf_extra.h so a cache issue does seem possible.
In any case all working now, I appreciate all the comments