Serial Buffer Size - How to adjust

Post here first, or if you can't find a relevant section!
Post Reply
timdelta
Posts: 9
Joined: Thu Jan 16, 2025 4:04 pm

Serial Buffer Size - How to adjust

Post 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?
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Serial Buffer Size - How to adjust

Post 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.
timdelta
Posts: 9
Joined: Thu Jan 16, 2025 4:04 pm

Re: Serial Buffer Size - How to adjust

Post 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?
ozcar
Posts: 176
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Serial Buffer Size - How to adjust

Post 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.
timdelta
Posts: 9
Joined: Thu Jan 16, 2025 4:04 pm

Re: Serial Buffer Size - How to adjust

Post 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
fpiSTM
Posts: 1944
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 108
Location: Le Mans
Contact:

Re: Serial Buffer Size - How to adjust

Post 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)
timdelta
Posts: 9
Joined: Thu Jan 16, 2025 4:04 pm

Re: Serial Buffer Size - How to adjust

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

Return to “General discussion”