uart: Provide support for esp32c2 and esp32h2

UART examples, unit test, and programming guide are all updated.
This commit is contained in:
songruojing
2022-01-17 20:32:39 +08:00
parent 6e0308d352
commit 24a60c12c6
19 changed files with 219 additions and 217 deletions

View File

@@ -25,7 +25,7 @@ To run this example, you need an ESP32, ESP32-S or ESP32-C series dev board (e.g
#### Pin Assignment:
**Note:** The following pin assignments are used by default which can be changed in `nmea_parser_config_t` structure.
**Note:** GPIO5 is used by default as the RX pin, you can change it by `idf.py menuconfig` > `Example Configuration` > `NMEA_PARSER_UART_RXD`.
| ESP | GPS |
| -------------------------- | --------------- |

View File

@@ -2,10 +2,12 @@ menu "Example Configuration"
config NMEA_PARSER_UART_RXD
int "UART RXD pin number"
range 0 34 if IDF_TARGET_ESP32
range 0 39 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2
range 0 48 if IDF_TARGET_ESP32S3
range 0 19 if IDF_TARGET_ESP32C3
range 0 18 if IDF_TARGET_ESP32C2
range 0 25 if IDF_TARGET_ESP32H2
default 5
help
GPIO number for UART RX pin. See UART documentation for more information

View File

@@ -1,16 +1,8 @@
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
@@ -149,17 +141,17 @@ typedef void *nmea_parser_handle_t;
* @brief Default configuration for NMEA Parser
*
*/
#define NMEA_PARSER_CONFIG_DEFAULT() \
{ \
.uart = { \
.uart_port = UART_NUM_1, \
.rx_pin = 2, \
.baud_rate = 9600, \
.data_bits = UART_DATA_8_BITS, \
.parity = UART_PARITY_DISABLE, \
.stop_bits = UART_STOP_BITS_1, \
.event_queue_size = 16 \
} \
#define NMEA_PARSER_CONFIG_DEFAULT() \
{ \
.uart = { \
.uart_port = UART_NUM_1, \
.rx_pin = CONFIG_NMEA_PARSER_UART_RXD,\
.baud_rate = 9600, \
.data_bits = UART_DATA_8_BITS, \
.parity = UART_PARITY_DISABLE, \
.stop_bits = UART_STOP_BITS_1, \
.event_queue_size = 16 \
} \
}
/**

View File

@@ -17,30 +17,30 @@ monitoring. The external interface should have 3.3V outputs. You may use e.g. 3.
Connect the external serial interface to the board as follows.
```
---------------------------------------------------------------------------------------
| Target chip Interface | #define | Default ESP Pin | External UART Pin |
| ----------------------|------------------|----------------------|--------------------
| Transmit Data (TxD) | EXAMPLE_UART_TXD | GPIO4 | RxD |
| Receive Data (RxD) | EXAMPLE_UART_RXD | GPIO5 | TxD |
| Ground | n/a | GND | GND |
---------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
| Target chip Interface | Kconfig Option | Default ESP Pin | External UART Pin |
| ----------------------|--------------------|----------------------|--------------------
| Transmit Data (TxD) | EXAMPLE_UART_TXD | GPIO4 | RxD |
| Receive Data (RxD) | EXAMPLE_UART_RXD | GPIO5 | TxD |
| Ground | n/a | GND | GND |
-----------------------------------------------------------------------------------------
```
Note: Some GPIOs can not be used with certain chips because they are reserved for internal use. Please refer to UART documentation for selected target.
Optionally, you can set-up and use a serial interface that has RTS and CTS signals in order to verify that the
hardware control flow works. Connect the extra signals according to the following table, configure both extra pins in
the example code by replacing existing `UART_PIN_NO_CHANGE` macros with the appropriate pin numbers and configure
UART1 driver to use the hardware flow control by setting `.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS` and adding
`.rx_flow_ctrl_thresh = 122`.
the example code `uart_echo_example_main.c` by replacing existing `UART_PIN_NO_CHANGE` macros with the appropriate pin
numbers and configure UART1 driver to use the hardware flow control by setting `.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS`
and adding `.rx_flow_ctrl_thresh = 122` to the `uart_config` structure.
```
--------------------------------------------------------------------------------------
| Target chip Interface | #define | Default ESP Pin | External UART Pin |
| ----------------------|-----------------|----------------------|--------------------
| Transmit Data (TxD) | ECHO_TEST_RTS | GPIO18 | CTS |
| Receive Data (RxD) | ECHO_TEST_CTS | GPIO19 | RTS |
| Ground | n/a | GND | GND |
--------------------------------------------------------------------------------------
---------------------------------------------------------------
| Target chip Interface | Macro | External UART Pin |
| ----------------------|-----------------|--------------------
| Transmit Data (TxD) | ECHO_TEST_RTS | CTS |
| Receive Data (RxD) | ECHO_TEST_CTS | RTS |
| Ground | n/a | GND |
---------------------------------------------------------------
```
### Configure the project

View File

@@ -4,8 +4,8 @@ menu "Echo Example Configuration"
int "UART port number"
range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
help
UART communication port number for the example.
See UART documentation for available port numbers.
@@ -19,10 +19,12 @@ menu "Echo Example Configuration"
config EXAMPLE_UART_RXD
int "UART RXD pin number"
range 0 34 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
range 0 39 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2
range 0 19 if IDF_TARGET_ESP32C3
range 0 47 if IDF_TARGET_ESP32S3
range 0 48 if IDF_TARGET_ESP32S3
range 0 18 if IDF_TARGET_ESP32C2
range 0 25 if IDF_TARGET_ESP32H2
default 5
help
GPIO number for UART RX pin. See UART documentation for more information
@@ -30,10 +32,12 @@ menu "Echo Example Configuration"
config EXAMPLE_UART_TXD
int "UART TXD pin number"
range 0 34 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
range 0 33 if IDF_TARGET_ESP32
range 0 45 if IDF_TARGET_ESP32S2
range 0 19 if IDF_TARGET_ESP32C3
range 0 47 if IDF_TARGET_ESP32S3
range 0 48 if IDF_TARGET_ESP32S3
range 0 18 if IDF_TARGET_ESP32C2
range 0 25 if IDF_TARGET_ESP32H2
default 4
help
GPIO number for UART TX pin. See UART documentation for more information

View File

@@ -1,11 +1,11 @@
| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 |
| ----------------- | ----- | -------- | -------- | -------- |
| Supported Targets | ESP32 | ESP32-S2 | ESP32-S3 | ESP32-C3 | ESP32-C2 | ESP32-H2 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- |
# UART RS485 Echo Example
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This is an example which echoes any data it receives on UART2 back to the sender in the RS485 network.
This is an example which echoes any data it receives on UART port back to the sender in the RS485 network.
It uses ESP-IDF UART software driver in RS485 half duplex transmission mode and requires external connection of bus drivers.
The approach demonstrated in this example can be used in user application to transmit/receive data in RS485 networks.
@@ -35,15 +35,15 @@ ESP32 BOARD | | RS-485 side | | SERIAL AD
#### Connect an external RS485 serial interface to an ESP32 board
Connect a USB-to-RS485 adapter to a computer, then connect the adapter's A/B output lines with the corresponding A/B output lines of the RS485 line driver connected to the ESP32 chip (see figure above).
```
--------------------------------------------------------------------------------------------------------------------------
| UART Interface | #define | Default ESP32 Pin | Default pins for | External RS485 Driver Pin |
| | | | ESP32-S2(S3, C3) | |
| ----------------------|--------------------|-----------------------|-----------------------|---------------------------|
| Transmit Data (TxD) | CONFIG_MB_UART_TXD | GPIO23 | GPIO9 | DI |
| Receive Data (RxD) | CONFIG_MB_UART_RXD | GPIO22 | GPIO8 | RO |
| Request To Send (RTS) | CONFIG_MB_UART_RTS | GPIO18 | GPIO10 | ~RE/DE |
| Ground | n/a | GND | GND | GND |
--------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------
| UART Interface | #define | Default ESP32 Pin | Default pins for | External RS485 Driver Pin |
| | | | ESP32-S2(S3, C3, C2, H2) | |
| ----------------------|--------------------|-----------------------|---------------------------|---------------------------|
| Transmit Data (TxD) | CONFIG_MB_UART_TXD | GPIO23 | GPIO9 | DI |
| Receive Data (RxD) | CONFIG_MB_UART_RXD | GPIO22 | GPIO8 | RO |
| Request To Send (RTS) | CONFIG_MB_UART_RTS | GPIO18 | GPIO10 | ~RE/DE |
| Ground | n/a | GND | GND | GND |
------------------------------------------------------------------------------------------------------------------------------
```
Note: Each target chip has different GPIO pins available for UART connection. Please refer to UART documentation for selected target for more information.

View File

@@ -4,8 +4,8 @@ menu "Echo RS485 Example Configuration"
int "UART port number"
range 0 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
default 2 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3
range 0 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
default 1 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
help
UART communication port number for the example.
See UART documentation for available port numbers.
@@ -19,36 +19,42 @@ menu "Echo RS485 Example Configuration"
config ECHO_UART_RXD
int "UART RXD pin number"
range 0 34 if IDF_TARGET_ESP32
range 0 39 if IDF_TARGET_ESP32
default 22 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2
range 0 47 if IDF_TARGET_ESP32S3
range 0 48 if IDF_TARGET_ESP32S3
range 0 19 if IDF_TARGET_ESP32C3
default 8 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3
range 0 18 if IDF_TARGET_ESP32C2
range 0 25 if IDF_TARGET_ESP32H2
default 8 if !IDF_TARGET_ESP32
help
GPIO number for UART RX pin. See UART documentation for more information
about available pin numbers for UART.
config ECHO_UART_TXD
int "UART TXD pin number"
range 0 34 if IDF_TARGET_ESP32
range 0 33 if IDF_TARGET_ESP32
default 23 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2
range 0 47 if IDF_TARGET_ESP32S3
range 0 45 if IDF_TARGET_ESP32S2
range 0 48 if IDF_TARGET_ESP32S3
range 0 19 if IDF_TARGET_ESP32C3
default 9 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3
range 0 18 if IDF_TARGET_ESP32C2
range 0 25 if IDF_TARGET_ESP32H2
default 9 if !IDF_TARGET_ESP32
help
GPIO number for UART TX pin. See UART documentation for more information
about available pin numbers for UART.
config ECHO_UART_RTS
int "UART RTS pin number"
range 0 34 if IDF_TARGET_ESP32
range 0 33 if IDF_TARGET_ESP32
default 18 if IDF_TARGET_ESP32
range 0 46 if IDF_TARGET_ESP32S2
range 0 47 if IDF_TARGET_ESP32S3
range 0 45 if IDF_TARGET_ESP32S2
range 0 48 if IDF_TARGET_ESP32S3
range 0 19 if IDF_TARGET_ESP32C3
default 10 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C3
range 0 18 if IDF_TARGET_ESP32C2
range 0 25 if IDF_TARGET_ESP32H2
default 10 if !IDF_TARGET_ESP32
help
GPIO number for UART RTS pin. This pin is connected to
~RE/DE pin of RS485 transceiver to switch direction.