How to set UART xon xoff characters?

zliudr
Posts: 360
Joined: Thu Oct 03, 2019 5:15 am

How to set UART xon xoff characters?

Postby zliudr » Thu Jun 24, 2021 3:12 pm

IDF V4.3 beta 1

I'm just going through the UART functions and structs. I noticed that there is a uart_sw_flowctrl_t struct that has threshold and both xon and xoff characters.

https://docs.espressif.com/projects/esp ... lowctrl_t

On the other hand, there is no function that uses this struct. The only function related is the uart_set_sw_flow_ctrl() that does NOT have the xon or xoff characters:
https://docs.espressif.com/projects/es ... _t7uint8_t

I also checked the source code. This uart_sw_flowctrl_t struct is not even defined let alone used. So is this planned, already implemented in latest or else? Thanks.

Leander
Posts: 28
Joined: Thu Sep 26, 2019 8:50 pm

Re: How to set UART xon xoff characters?

Postby Leander » Mon Jun 13, 2022 8:37 am

The struct is used in the uart.c file when calling the SW Flow Conrol function.

Code: Select all

esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable,  uint8_t rx_thresh_xon,  uint8_t rx_thresh_xoff)
{
    ESP_RETURN_ON_FALSE((uart_num < UART_NUM_MAX), ESP_FAIL, UART_TAG, "uart_num error");
    ESP_RETURN_ON_FALSE((rx_thresh_xon < SOC_UART_FIFO_LEN), ESP_FAIL, UART_TAG, "rx flow xon thresh error");
    ESP_RETURN_ON_FALSE((rx_thresh_xoff < SOC_UART_FIFO_LEN), ESP_FAIL, UART_TAG, "rx flow xoff thresh error");
    uart_sw_flowctrl_t sw_flow_ctl = {
        .xon_char = XON,
        .xoff_char = XOFF,
        .xon_thrd = rx_thresh_xon,
        .xoff_thrd = rx_thresh_xoff,
    };
    UART_ENTER_CRITICAL(&(uart_context[uart_num].spinlock));
    uart_hal_set_sw_flow_ctrl(&(uart_context[uart_num].hal), &sw_flow_ctl, enable);
    UART_EXIT_CRITICAL(&(uart_context[uart_num].spinlock));
    return ESP_OK;
}
It doesn't mean that you can determine the xon and xoff characters.
The XON and XOFF are defined as the default ASCII characters 0x13 and 0x11 just as the UART protocol describes

Code: Select all

#define XOFF (0x13)
#define XON (0x11)

Who is online

Users browsing this forum: No registered users and 230 guests