Skip to main content
Associate
April 9, 2025
Question

STM32duino: Serial Seiral1 etc RXBuffer size

  • April 9, 2025
  • 4 replies
  • 649 views

I using STM32duino to program the STM32F103C8T6. When I use the Seiral1 to communicate with a 4G, the data reveived exceeds 64 characters, data will lost. By using modify the following #defines, it does not working. I am appreciated if somebody could help. The folowing test prgram file is as following:

#define SERIAL_RX_BUFFER_SIZE 1024
#include <Arduino.h>


char str[] = "config,netchaninfo,ok,tcp,uart,0,0,00,60,47.192.1.114,22004,0,,0,,0,,0,0";
char *endptr;

uint8_t uxBuffer[256] = {0};
uint16_t uxLen = 0;
uint8_t timeout = 20;
uint8_t ux = 0;

long long x64 = 869020060303565;
long long x64_1 = 0;

void setup()
{
    Serial.begin(115200);
    delay(5000);
    //int x = SERIAL_TX_BUFFER_SIZE;
    Serial.printf("SERIAL TX BUFFER SIZE = %d\n", SERIAL_TX_BUFFER_SIZE);
    Serial.printf("%s\n", str);
    Serial.printf("size of str = %d\n", sizeof(str));

}

void loop()
{
    if ( Serial.available())
    {
        ux++;
        if ( ux > timeout)
        {
            uxLen = Serial.available();
            Serial.printf("string len = %d\n", uxLen);
            ux = 0;
            for ( int i = 0; i < uxLen; i++)
            {
                uxBuffer[i] = Serial.read();
            }
        }
    }
}

4 replies

Pavel A.
Super User
April 9, 2025

Here you can find help and advice on your project.

Andrew Neil
Super User
April 9, 2025

Please see How to insert source code.

 


@caixf wrote:

I using STM32duino


Then this is the place to post: https://www.stm32duino.com/

Maybe also in the Arduino forums: https://forum.arduino.cc/

 

Note that these forums will also have requirements for posting source code to keep it legible.

 

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
caixfAuthor
Associate
April 9, 2025

@Andrew Neil 

Thank you for your information.

ST Employee
August 29, 2025

When you define in the sketch file (.ino) it is not defined globally as it is converted as a .cpp file.

To properly redefine the 

SERIAL_RX_BUFFER_SIZE

you have to create a file named build_opt.h and add:

-DSERIAL_RX_BUFFER_SIZE=1024

Like this is properly redefined globally.

See the wiki for more information.

https://github.com/stm32duino/Arduino_Core_STM32/wiki/Customize-build-options-using-build_opt.h#examples-of-file-content