Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

takanori
Posts: 6
Joined: Wed Sep 17, 2025 6:47 am

Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby takanori » Thu Sep 18, 2025 4:18 am

I'm using ESP32-S3 and encountering occasional delays when sending more than 128 bytes (e.g., 200 bytes) via uart_write_bytes().
Normally, the notification completes within about 10ms, but sometimes it takes between 50ms and 200ms.
Even after setting the task priority to the maximum (24), the issue still occurs.
I suspect that some interrupt handling inside ESP-IDF might be causing this behavior.
Does anyone know what might be causing this or how to resolve it?
Best regards,

Sprite
Espressif staff
Espressif staff
Posts: 10612
Joined: Thu Nov 26, 2015 4:08 am

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby Sprite » Thu Sep 18, 2025 10:09 am

What's your baud rate? I'm thinking that normally the data fits into the FIFO buffer of the UART, but <128 bytes won't fit and as such the write blocks until the first block of data has been sent.

takanori
Posts: 6
Joined: Wed Sep 17, 2025 6:47 am

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby takanori » Thu Sep 18, 2025 10:34 am

The baud rate is 115200. Since the TX buffer size specified in uart_driver_install() is 0, I assume the FIFO buffer is using the default size of 128 bytes.

MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby MicroController » Fri Sep 19, 2025 8:38 am

Baudrate 115200 = 11520 bytes/s max -> 1ms/11.5 bytes

takanori
Posts: 6
Joined: Wed Sep 17, 2025 6:47 am

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby takanori » Thu Oct 02, 2025 8:27 am

This issue involves sending 200 bytes of data, for example.
After transmitting the first 128 bytes, an interval of 50 to 200 milliseconds occurs,
followed by the transmission of the remaining 72 bytes.

This behavior has been confirmed using an oscilloscope.

We would like to understand why this behavior occurs and request a solution.

MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby MicroController » Thu Oct 02, 2025 7:13 pm

You say that something like

Code: Select all

uart_write_bytes(UART_PORT,buffer,200);
causes a 50-200ms pause on the UART TX in the middle of the transmission?

More code needed.

takanori
Posts: 6
Joined: Wed Sep 17, 2025 6:47 am

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby takanori » Fri Oct 03, 2025 4:10 am

causes a 50-200ms pause on the UART TX in the middle of the transmission?
Yes,the following processing is implemented, causing a pause of 50 to 200 milliseconds during transfer.
The task running this process has the highest priority.

Code: Select all

    uart_write_bytes(UART_NUM_1, buffer, 200);

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby ok-home » Fri Oct 03, 2025 6:45 am

causes a 50-200ms pause on the UART TX in the middle of the transmission?
Yes,the following processing is implemented, causing a pause of 50 to 200 milliseconds during transfer.
The task running this process has the highest priority.

Code: Select all

    uart_write_bytes(UART_NUM_1, buffer, 200);
Maybe I'm doing something wrong.
Sending 500 bytes, without any intervals.
For example, a screenshot from the analyzer - 120-140 characters.

Code: Select all

static const int RX_BUF_SIZE = 1024;
static const int RX_DATA_SIZE = 550;
static const int TX_DATA_SIZE = 500;
// esp32s3 free pin
#define TXD_PIN (GPIO_NUM_1)
#define RXD_PIN (GPIO_NUM_2)

void init(void)
{
    const uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_DEFAULT,
    };
    // We won't use a buffer for sending data.
    uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
    uart_param_config(UART_NUM_1, &uart_config);
    uart_set_pin(UART_NUM_1, TXD_PIN, TXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);

// connect RX & TX pin without wire, reeset tx connection
    gpio_set_direction(TXD_PIN, GPIO_MODE_INPUT_OUTPUT);
    esp_rom_gpio_connect_out_signal(TXD_PIN, UART_PERIPH_SIGNAL(UART_NUM_1, SOC_UART_TX_PIN_IDX), 0, 0);

}

static void tx_task(void *arg)
{
    static const char *TX_TASK_TAG = "TX_TASK";
    uint8_t* data_txd = (uint8_t*) calloc(TX_DATA_SIZE + 1,1);
    //memset(data_txd, 0x55, TX_DATA_SIZE);
    esp_log_level_set(TX_TASK_TAG, ESP_LOG_INFO);
    while (1) {
        const int txBytes = uart_write_bytes(UART_NUM_1, data_txd, TX_DATA_SIZE);
        ESP_LOGI("UART_TX_TASK", "Wrote %d bytes", txBytes);
        vTaskDelay(2000 / portTICK_PERIOD_MS);
    }
}

static void rx_task(void *arg)
{
    static const char *RX_TASK_TAG = "RX_TASK";
    esp_log_level_set(RX_TASK_TAG, ESP_LOG_INFO);
    uint8_t* data = (uint8_t*) malloc(RX_DATA_SIZE + 1);
    while (1) {
        const int rxBytes = uart_read_bytes(UART_NUM_1, data, RX_DATA_SIZE, 1000 / portTICK_PERIOD_MS);
        if (rxBytes > 0) {
            data[rxBytes] = 0;
            ESP_LOGI(RX_TASK_TAG, "Read %d bytes", rxBytes);
        }
    }
    free(data);
}
void app_main(void)
{
    //logic_analyzer_cli();
    init();
    xTaskCreate(rx_task, "uart_rx_task", 1024 * 4, NULL, 5, NULL);
    xTaskCreate(tx_task, "uart_tx_task", 1024 * 4, NULL, 5, NULL);
    }

uart.JPG
uart.JPG (95.92 KiB) Viewed 2394 times

takanori
Posts: 6
Joined: Wed Sep 17, 2025 6:47 am

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby takanori » Thu Oct 09, 2025 10:54 am

Code: Select all

    const uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_DEFAULT,
    };
    // We won't use a buffer for sending data.
    uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
The differences from my environment are as follows.
.parity = UART_PARITY_EVEN,
.source_clk = UART_SCLK_APB,
  RX_BUF_SIZE * 2・・・18KB
Could these differences be affecting it...?
Could you please try it with the same settings?

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Delay or interrupt when sending more than 128 bytes via UART on ESP32-S3

Postby ok-home » Fri Oct 10, 2025 1:43 am

The differences from my environment are as follows.
.parity = UART_PARITY_EVEN,
.source_clk = UART_SCLK_APB,
  RX_BUF_SIZE * 2・・・18KB
Could these differences be affecting it...?
Could you please try it with the same settings?
no difference at speeds from 115200 to 1500000

Who is online

Users browsing this forum: ChatGPT-User, Google [Bot] and 1 guest