Skip to content

Commit c465b75

Browse files
committed
docs(uart): aligned the config order in the programming guide with examples
Closes #13182
1 parent f38a2e1 commit c465b75

File tree

2 files changed

+62
-68
lines changed

2 files changed

+62
-68
lines changed

docs/en/api-reference/peripherals/uart.rst

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ Functional Overview
2323

2424
The overview describes how to establish communication between an {IDF_TARGET_NAME} and other UART devices using the functions and data types of the UART driver. A typical programming workflow is broken down into the sections provided below:
2525

26-
1. :ref:`uart-api-setting-communication-parameters` - Setting baud rate, data bits, stop bits, etc.
27-
2. :ref:`uart-api-setting-communication-pins` - Assigning pins for connection to a device
28-
3. :ref:`uart-api-driver-installation` - Allocating {IDF_TARGET_NAME}'s resources for the UART driver
26+
1. :ref:`uart-api-driver-installation` - Allocating {IDF_TARGET_NAME}'s resources for the UART driver
27+
2. :ref:`uart-api-setting-communication-parameters` - Setting baud rate, data bits, stop bits, etc.
28+
3. :ref:`uart-api-setting-communication-pins` - Assigning pins for connection to a device
2929
4. :ref:`uart-api-running-uart-communication` - Sending/receiving data
3030
5. :ref:`uart-api-using-interrupts` - Triggering interrupts on specific communication events
3131
6. :ref:`uart-api-deleting-driver` - Freeing allocated resources if a UART communication is no longer required
@@ -39,13 +39,39 @@ Steps 1 to 3 comprise the configuration stage. Step 4 is where the UART starts o
3939
The UART driver's functions identify each of the UART controllers using :cpp:type:`uart_port_t`. This identification is needed for all the following function calls.
4040

4141

42+
.. _uart-api-driver-installation:
43+
44+
Install Drivers
45+
^^^^^^^^^^^^^^^^^^^
46+
47+
First of all, install the driver by calling :cpp:func:`uart_driver_install` and specify the following parameters:
48+
49+
- UART port number
50+
- Size of RX ring buffer
51+
- Size of TX ring buffer
52+
- Event queue size
53+
- Pointer to store the event queue handle
54+
- Flags to allocate an interrupt
55+
56+
.. _driver-code-snippet:
57+
58+
The function allocates the required internal resources for the UART driver.
59+
60+
.. code-block:: c
61+
62+
// Setup UART buffered IO with event queue
63+
const int uart_buffer_size = (1024 * 2);
64+
QueueHandle_t uart_queue;
65+
// Install UART driver using an event queue here
66+
ESP_ERROR_CHECK(uart_driver_install({IDF_TARGET_UART_EXAMPLE_PORT}, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
67+
68+
4269
.. _uart-api-setting-communication-parameters:
4370

4471
Set Communication Parameters
4572
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4673

47-
UART communication parameters can be configured all in a single step or individually in multiple steps.
48-
74+
As the next step, UART communication parameters can be configured all in a single step or individually in multiple steps.
4975

5076
Single Step
5177
"""""""""""
@@ -113,35 +139,6 @@ The same macro :c:macro:`UART_PIN_NO_CHANGE` should be specified for pins that w
113139
// Set UART pins(TX: IO4, RX: IO5, RTS: IO18, CTS: IO19)
114140
ESP_ERROR_CHECK(uart_set_pin({IDF_TARGET_UART_EXAMPLE_PORT}, 4, 5, 18, 19));
115141
116-
.. _uart-api-driver-installation:
117-
118-
Install Drivers
119-
^^^^^^^^^^^^^^^^^^^
120-
121-
Once the communication pins are set, install the driver by calling :cpp:func:`uart_driver_install` and specify the following parameters:
122-
123-
- UART port number
124-
- Size of TX ring buffer
125-
- Size of RX ring buffer
126-
- Pointer to store the event queue handle
127-
- Event queue size
128-
- Flags to allocate an interrupt
129-
130-
.. _driver-code-snippet:
131-
132-
The function allocates the required internal resources for the UART driver.
133-
134-
.. code-block:: c
135-
136-
// Setup UART buffered IO with event queue
137-
const int uart_buffer_size = (1024 * 2);
138-
QueueHandle_t uart_queue;
139-
// Install UART driver using an event queue here
140-
ESP_ERROR_CHECK(uart_driver_install({IDF_TARGET_UART_EXAMPLE_PORT}, uart_buffer_size, \
141-
uart_buffer_size, 10, &uart_queue, 0));
142-
143-
Once this step is complete, you can connect the external UART device and check the communication.
144-
145142
146143
.. _uart-api-running-uart-communication:
147144

docs/zh_CN/api-reference/peripherals/uart.rst

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
下文介绍了如何使用 UART 驱动程序的函数和数据类型在 {IDF_TARGET_NAME} 和其他 UART 设备之间建立通信。基本编程流程分为以下几个步骤:
2525

26-
1. :ref:`uart-api-setting-communication-parameters` - 设置波特率、数据位、停止位等
27-
2. :ref:`uart-api-setting-communication-pins` - 分配连接设备的管脚
28-
3. :ref:`uart-api-driver-installation` - 为 UART 驱动程序分配 {IDF_TARGET_NAME} 资源
26+
1. :ref:`uart-api-driver-installation` - 为 UART 驱动程序分配 {IDF_TARGET_NAME} 资源
27+
2. :ref:`uart-api-setting-communication-parameters` - 设置波特率、数据位、停止位等
28+
3. :ref:`uart-api-setting-communication-pins` - 分配连接设备的管脚
2929
4. :ref:`uart-api-running-uart-communication` - 发送/接收数据
3030
5. :ref:`uart-api-using-interrupts` - 触发特定通信事件的中断
3131
6. :ref:`uart-api-deleting-driver` - 如无需 UART 通信,则释放已分配的资源
@@ -39,13 +39,39 @@
3939
UART 驱动程序函数通过 :cpp:type:`uart_port_t` 识别不同的 UART 控制器。调用以下所有函数均需此标识。
4040

4141

42+
.. _uart-api-driver-installation:
43+
44+
安装驱动程序
45+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
47+
首先,请调用 :cpp:func:`uart_driver_install` 安装驱动程序并指定以下参数:
48+
49+
- UART 控制器编号
50+
- Rx 环形缓冲区的大小
51+
- Tx 环形缓冲区的大小
52+
- 事件队列大小
53+
- 指向事件队列句柄的指针
54+
- 分配中断的标志
55+
56+
.. _driver-code-snippet:
57+
58+
该函数将为 UART 驱动程序分配所需的内部资源。
59+
60+
.. code-block:: c
61+
62+
// Setup UART buffered IO with event queue
63+
const int uart_buffer_size = (1024 * 2);
64+
QueueHandle_t uart_queue;
65+
// Install UART driver using an event queue here
66+
ESP_ERROR_CHECK(uart_driver_install({IDF_TARGET_UART_EXAMPLE_PORT}, uart_buffer_size, uart_buffer_size, 10, &uart_queue, 0));
67+
68+
4269
.. _uart-api-setting-communication-parameters:
4370

4471
设置通信参数
4572
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4673

47-
UART 通信参数可以在一个步骤中完成全部配置,也可以在多个步骤中单独配置。
48-
74+
其次,UART 通信参数可以在一个步骤中完成全部配置,也可以在多个步骤中单独配置。
4975

5076
一次性配置所有参数
5177
""""""""""""""""""""""""""""""""
@@ -113,35 +139,6 @@ UART 通信参数可以在一个步骤中完成全部配置,也可以在多个
113139
// Set UART pins(TX: IO4, RX: IO5, RTS: IO18, CTS: IO19)
114140
ESP_ERROR_CHECK(uart_set_pin({IDF_TARGET_UART_EXAMPLE_PORT}, 4, 5, 18, 19));
115141
116-
.. _uart-api-driver-installation:
117-
118-
安装驱动程序
119-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120-
121-
通信管脚设置完成后,请调用 :cpp:func:`uart_driver_install` 安装驱动程序并指定以下参数:
122-
123-
- UART 控制器编号
124-
- Tx 环形缓冲区的大小
125-
- Rx 环形缓冲区的大小
126-
- 指向事件队列句柄的指针
127-
- 事件队列大小
128-
- 分配中断的标志
129-
130-
.. _driver-code-snippet:
131-
132-
该函数将为 UART 驱动程序分配所需的内部资源。
133-
134-
.. code-block:: c
135-
136-
// Setup UART buffered IO with event queue
137-
const int uart_buffer_size = (1024 * 2);
138-
QueueHandle_t uart_queue;
139-
// Install UART driver using an event queue here
140-
ESP_ERROR_CHECK(uart_driver_install({IDF_TARGET_UART_EXAMPLE_PORT}, uart_buffer_size, \
141-
uart_buffer_size, 10, &uart_queue, 0));
142-
143-
此步骤完成后,可连接外部 UART 设备检查通信。
144-
145142
146143
.. _uart-api-running-uart-communication:
147144

0 commit comments

Comments
 (0)